How do I get x to become a 1D array? I found it convenient to create x like 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 also tried making it like this, but the length is 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 and y):
np.reshape(x,48)
but I get this error:
ValueError: total size of new array must be unchanged
Is it possible to reshape x or y when I have declared them like I did?
When you create the array, concatenate the lists with
+
instead of packing them in another list: