python - How to reshape this numpy array to exclude the "extra dimension"? -


i have numpy array arr1 output of function. array has "extra" dimension caused each element inside numpy array being cast numpy array itself.

arr1.shape outputs (100, 20, 1)

if print array, print(arr1[0]) outputs

array([[-212537.61715316],        [   7258.38476409],        [  37051.91250884],        [-146278.00512207],        [-185792.24620168],        [-200794.59538468],        [-195981.27879612],        [-177912.26034464],        [-152212.805867  ],        [-118873.26452198],        [ -64657.64682999],        [ 306884.11196766],        [-191073.9891907 ],        [-104992.44840277],        [ -67834.43041102],        [ -21810.77063542],        [  17307.24511071],        [  55607.49775471],        [  91259.82533592],        [ 119207.40589797]]) 

if reshape arr1.reshape((100,20)), following output print(arr1.reshape((100,20))[0]):

array([-212537.61715316,    7258.38476409,   37051.91250884,        -146278.00512207, -185792.24620168, -200794.59538468,        -195981.27879612, -177912.26034464, -152212.805867  ,        -118873.26452198,  -64657.64682999,  306884.11196766,        -191073.9891907 , -104992.44840277,  -67834.43041102,         -21810.77063542,   17307.24511071,   55607.49775471,          91259.82533592,  119207.40589797]) 

my question is: how exclude "extra" one, retain original shape of array arr1?

is best method use .reshape()? if not, best way this?

you using reshape correctly.

 arr2 = arr1.reshape((100,20)) 

the shape of (100,20), same arr1 without last dimension.

arr1[0] has shape (20,1), , prints column.

arr2[0] has shape (20,), , prints row(s) (count brackets). might not display, shape correct.

squeeze can used take out dimension, results same.

print(arr2[0][:,none]) should print column. adds dimension on prior printing.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -