我的想法是,我是一个学生,只是采取一些数据的一些实验,我需要表示在一个表中。我使用了一个数组来存储用户输入的所有数据,但是我正在寻找一种更有效的方法来表示我的数据。你知道吗
这是我的密码:
import numpy as np
print 'Times, Average Times, Velocity'
tteb=np.zeros((3,7))
pos=np.array([1000,950,850,700,500,250,0])
posp=pos*(5.16667*10**(-4))
for j in range (0,3):
k=j+1
print 'This is for trial %d' %k
for i in range (0,7):
print 'Input for band %d'%i
tteb[j,i]=float(raw_input('~'))
print 'Trials 1-3 for all 7 bands.:'
print tteb
raw_input('Press [Enter] to continue to average time and *velocity *(later).')
ttebatvsum=tteb.sum(axis=0)
print 'This is all the times added together. (Bands 0--->6).'
print ttebatvsum
print 'This is the average for all of the times. (Bands 0--->6).'
ttebatvmean=ttebatvsum/3
print ttebatvmean
raw_input('Press [Enter] to continue to velocity.')
velocity=posp/ttebatvsum
print 'Here are all the velocities. (Bands 0--->6).'
print velocity
#Table Starts here
print 'Pos (ml) |Pos (m) | t1 |t2 | t3 |t(avg) |v |'
print '%2.3f |%4.3f |%6.3f |%8.3f |%10.3f |%12.3f |%14.3f |'%(pos[0],posp[0],tteb[0,0],tteb[1,0],tteb[2,0],ttebatvmean[0],velocity[0])
print '%2.3f |%4.3f |%6.3f |%8.3f |%10.3f |%12.3f |%14.3f |'%(pos[1],posp[1],tteb[0,1],tteb[1,1],tteb[2,1],ttebatvmean[1],velocity[1])
print '%2.3f |%4.3f |%6.3f |%8.3f |%10.3f |%12.3f |%14.3f |'%(pos[2],posp[2],tteb[0,2],tteb[1,2],tteb[2,2],ttebatvmean[2],velocity[2])
print '%2.3f |%4.3f |%6.3f |%8.3f |%10.3f |%12.3f |%14.3f |'%(pos[3],posp[3],tteb[0,3],tteb[1,3],tteb[2,3],ttebatvmean[3],velocity[3])
print '%2.3f |%4.3f |%6.3f |%8.3f |%10.3f |%12.3f |%14.3f |'%(pos[4],posp[4],tteb[0,4],tteb[1,4],tteb[2,4],ttebatvmean[4],velocity[4])
print '%2.3f |%4.3f |%6.3f |%8.3f |%10.3f |%12.3f |%14.3f |'%(pos[5],posp[5],tteb[0,5],tteb[1,5],tteb[2,5],ttebatvmean[5],velocity[5])
print '%2.3f |%4.3f |%6.3f |%8.3f |%10.3f |%12.3f |%14.3f |'%(pos[6],posp[6],tteb[0,6],tteb[1,6],tteb[2,6],ttebatvmean[6],velocity[6])
我的想法是在我的例子中使用for循环。我想让数组的数字以1的增量递增
另一种方法是在numpy中将数据格式化为一个表,然后输出整个数据。还可以使用
format
更好地控制字符串的显示方式。你知道吗如果不想将所有数据放在一个数组中,也可以
zip
将数组放在一起输出:看看这组线条:
如果我们有一个变量
j
,它从零开始,我们可以写:所以我们可以把它放在一个循环中:
但是,请注意you can print without a newline (carriage return),因此您不必在一行上完成
tteb
。实际上,你可以这样做:把它放进去:
希望您能看到,我们可以将书写分解为更易于管理的块,并在需要时在一行中使用循环。你知道吗
NB:我不确定您对那里的打印格式做了什么,格式应该类似于'%8.3f',表示数字的8个字符总数,在固定精度格式中有3位数的精度。8不应该改变,除非你想在小数点前增加或减少数字。你知道吗
相关问题 更多 >
编程相关推荐