x and y must have same first dimension, but have shapes (1, 400) and (400,)
I have search this forum and saw that people suggested to do np.array to solve this, but it didn't seem to work.
def function(a, v):
speedx = 0.0
yt = -1.0
val = []
for i in len(a):
xt = a[0]
vx = -2.0 * yt**2 * xt * (1 - xt**3)
vy = -2.0 * xt**2 * yt * (1 - yt**3)
angle = np.atan2(vy,vx)
val.append(angle)
return np.array([val])
rge = np.arange(-0.2, 0.2, 0.001)
a = np.array(rg)
speedy = 0.1 #vy
ans = odeint(function, a, speedy)
plt.plot(ans, a)
When you return np.array([val])
, that makes a two dimensional array because val
is already an array. That is why the shape is (1,400) which makes it two dimensional with the size of the first dimension being 1. You can try:
return np.array(val)
That may help. Also, the code you have pasted has obvious bugs which I am assuming are typos like angle.append
should have been val.append
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.