Ich versuche, ein Array in Python innerhalb eines Arrays zu machen, die wie folgt aussieht:sie ein Array innerhalb eines Arrays in Python
[[3,0,-3,-4],[6,0,-2.44,-4]]
, die ich in einem Vektordiagramm in matplotlib nutzen könnte.
Ich habe versucht, dies mit folgendem Programm zu tun:
data = np.loadtxt(sys.argv[1], dtype='str',delimiter=',', skiprows=1, usecols=(0,1,2,3,4,5,6,7))
x = data[:,0].astype(float)
u = data[:,6].astype(float)
v = data[:,7].astype(float)
soa = []
for t in range(0,2):
print "At time ",x[t]," U is ",u[t]," and V is ",v[t]
result = [x[t],0,u[t],v[t]]
soa = np.append(soa, [result])
print "soa is ",soa
Wenn ich das Programm laufen bekomme ich die Ausgabe:
soa ist [3. 0. -3. -4. 6. 0. -2.44 -4. ]
Dies kann nicht als Vektorplot in Matplotlib geplottet werden. Wie kann ich das Skript zwicken das Array in das Format zu erhalten:
[[3,0,-3,-4],[6,0,-2.44,-4]]
wo [3,0, -3, -4] und [6,0, -2,44, -4] sind Vektoren, die ich könnte in Matplotlib plotten?
schnelle Lösung setzen, 'soa = soa.reshape ((2, -1)) ' –