I have a feeling that this is very easy but I can't quite figure out how to do it. Say I have a Numpy array
[1,2,3,4]
How do I convert this to
[[1],[2],[3],[4]]
In an easy way?
Thanks
You can use numpy.reshape:
>>> import numpy as np
>>> a = np.array([1,2,3,4])
>>> np.reshape(a, (-1, 1))
array([[1],
[2],
[3],
[4]])
If you want normal python list then use list comprehension:
>>> a = np.array([1,2,3,4])
>>> [[x] for x in a]
[[1], [2], [3], [4]]
np.array([1, 2, 3, 4])tonp.array([[1], [2], [3], [4]])? Or convert it to a traditional Python list of lists?