Communities for your favorite technologies. Explore all Collectives
Ask questions, find answers and collaborate at work with Stack Overflow for Teams.
Ask questions, find answers and collaborate at work with Stack Overflow for Teams. Explore Teams
Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
I would like to know how I can add row to a matrix in python numpy. For instance, in Matlab we can do A=[1;zeros(10,1)], how can I do that in numpy?
A=[1;zeros(10,1)]
Thanks.
np.hstack
np.vstack
cat
horzcat
vertcat
numpy
concatenate
hstack
vstack
np.array
Try this:
import numpy ... # L is your 2-dimensional list M = numpy.matrix(L) # R is the list (i.e. a row) to add M = numpy.vstack([M, R])
Add a comment
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
np.hstackandnp.vstackfor examplecat,horzcatandvertcatfunctions. Innumpyconcatenateis the basic function,hstackandvstackuse it. Make sure you understand dimensions (especially the fact thatnp.arraymay have 0 or 1 dim, not just 2.