Issue
How do you reshape 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 loop
produces 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
Answered By - minolee
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.