Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to convert items of array into array themselves Python

My problem is that I've got this array:

np.array([0.0, 0.0, -1.2, -1.2, -3.4, -3.4, -4.5, -4.5])

and I want to convert the elements to array like this:

np.array([[0.0], [0.0], [-1.2], [-1.2], [-3.4], [-3.4], [-4.5], [-4.5]])

So is there a loop or a numpy function that I could use to do this task?

like image 969
Elie Dumas-Lefebvre Avatar asked Nov 28 '22 13:11

Elie Dumas-Lefebvre


1 Answers

Or simply:

arr[:,None]

# array([[ 0. ],
#        [ 0. ],
#        [-1.2],
#        [-1.2],
#        [-3.4],
#        [-3.4],
#        [-4.5],
#        [-4.5]])
like image 170
Psidom Avatar answered Dec 20 '22 11:12

Psidom