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

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

c# - Search and Add Comment with OpenXML for Word -