python - Numpy reshape array of arrays to 1D -


how x become 1d array? found convenient create x this,

x=np.array([[0,-1,0]*12,[-1,0,0]*4]) print x print len(x) 

returns

array([ [0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0],        [-1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0]], dtype=object)  2 

i tried making this, length still 2

y=((0,1,0)*12,(-1,0,0)*4) print y 

returns

((0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0), (-1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0)) 

i have tried using numpy.reshape (on both x , y):

np.reshape(x,48) 

but error:

valueerror: total size of new array must unchanged 

is possible reshape x or y when have declared them did?

when create array, concatenate lists + instead of packing them in list:

x = np.array([0,-1,0]*12 + [-1,0,0]*4) 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

Kivy: Swiping (Carousel & ScreenManager) -

jdbc - Not able to establish database connection in eclipse -