Python numpy reshape from (n,) to (n, 1 , 1)

Viewed 32

I have an array defined like the following:

array([ 0.1394957,  0.16518061,  0.15289813,  0.14116833 ])

and I would like to reshape to something like:

array([[[0.1394957 ]],

   [[0.16518061]],

   [[0.15289813]],

   [[0.14116833]]])

The starting shape is (n,) and I would like to get (n, 1, 1)

I tried the following approach:

newarr = arr.reshape(len(arr), 1, -1) Is there another way?

0 Answers
Related