I am trying to vectorize the following loop in I am trying to append multiple arrays to an empty array.
# ff is a matrix of shape [100,1,96]
temp = np.array([]).reshape(0,96)
for kk in range(1,10,1):
temp = np.append(tr,ff[kk],axis=0)
temp = temp.reshape(1,10,96)
Is it possible to vectorize the above loop using numpy? Any help is welcome!
You can use slicing to extract the data you need:
ff[:10,:,:]
That will yield an array of shape (10, 1, 96). To get rid of the empty dimension, you can run it through numpy.squeeze():
numpy.squeeze(ff[:10,:,:])
and get an array of shape (10, 96)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With