I want to add a numpy array to another numpy array:
x = np.ones((3))
y = np.zeros((3))
and if we print it we have:
array([ 1., 1., 1.])
array([ 0., 0., 0.])
I try to concatenate, append or insert x in y but it didn't work.
I want this numpy array:
[[0,0,0], [1,1,1]]
for instance in python:
example = []
test = [2,2,2]
test2 = [3,3,3]
example.append(test)
example.append(test2)
print(example)
Out:
[[2, 2, 2], [3, 3, 3]]
as you can see, python add test and test2 as a list, and example became a list of list. But in numpy i don't manage to have a array of array like that:
array([[2, 2, 2], [3, 3, 3]])
This array should have a length == 2. If I add an other array, length == 3. Numpy concatenate the two array and not create an array of array:
x = np.ones((3))
y = np.zeros((3))
z = np.concatenate((x,y)) #Out: array([ 2., 1., 1., 0., 0., 0.])
z = np.append(x,y) # Out : array([ 2., 1., 1., 0., 0., 0.])
z = np.insert(x,0,y) # Out: array([ 0., 0., 0., 2., 1., 1.])
z = np.array((x,y)) # Out array([[ 2., 1., 1.],
#[ 0., 0., 0.]])
the last Out is almost good but if I do that:
w = np.array((2,3,4))
z = np.array((z,w)) # Out: array([array([[ 2., 1., 1.],
#[ 0., 0., 0.]]), array([2, 3, 4])], dtype=object)
It creates array(array(z), array(w)) and not array(array(z[0], z[1],...z[-1], w).