I have a numpy array, which might look something like this
[[1 2]
[3 4]]
I would like to convert it to have one extra dimension, as such:
[[[1]
[2]]
[[3]
[4]]]
Is there a simple way to do this?
I have a numpy array, which might look something like this
[[1 2]
[3 4]]
I would like to convert it to have one extra dimension, as such:
[[[1]
[2]]
[[3]
[4]]]
Is there a simple way to do this?
Use np.newaxis
and tolist
:
a = np.array([[1, 2], [3, 4]])
a[:, :, np.newaxis].tolist()
Output:
[[[1], [2]], [[3], [4]]]