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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -