0

I have the following numpy array

a= np.array([1,1])

I have the two elements

b= [2, 2]
c= [3, 3]

I would like to add those elements b and c, so that my output seems like this

a= [[1, 1],
    [2, 2].
    [3, 3]], #shape=(3,2) 

which numpy function should i use? thanks

1 Answer 1

1

Create a new numpy array with the three elements

>>> np.array([a,b,c])
array([[1, 1],
   [2, 2],
   [3, 3]])
# shape : (3, 2)

If a had more than 1 dimension, np.append can be used :

>>> a= np.array([[1,1], [4,4]])
>>> a
array([[1, 1],
       [4, 4]])
>>> np.append(a,[b],axis=0)
array([[1, 1],
       [4, 4],
       [2, 2]])
Sign up to request clarification or add additional context in comments.

2 Comments

yes this worked fine thanks, but havin two elements in the a array (a= np.array([[1,1], [4,4]])) makes it impossible to add the elements b and c with this solution. do u have suggestions to solve it ?thnx
@ABA added an edit with this

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.