How do you reshape from a (55, 11) numpy array to a (55, 11, 1) numpy array?
Attempts:
- Simply doing
numpy_array.reshape(-1, 1)without any loop produces a flat array that is not 3D. - The following
for loopproduces a "cannot
broadcast error":
for i in range(len(numpy_array)):
numpy_array[i] = numpy_array[i].reshape(-1, 1)
>Solution :
Maybe you are looking for numpy.expand_dims(https://numpy.org/doc/stable/reference/generated/numpy.expand_dims.html)?
import numpy
a = numpy.random.rand(55,11)
print(a.shape) # 55,11
print(numpy.expand_dims(a, 2).shape) # 55, 11, 1