How do I create an empty array/matrix in NumPy?
Posted
by Ben
on Stack Overflow
See other posts from Stack Overflow
or by Ben
Published on 2009-02-20T09:58:11Z
Indexed on
2010/04/01
12:13 UTC
Read the original article
Hit count: 433
I'm sure I must be being very dumb, but I can't figure out how to use an array or matrix in the way that I would normally use a list. I.e., I want to create an empty array (or matrix) and then add one column (or row) to it at a time.
At the moment the only way I can find to do this is like:
mat = None
for col in columns:
if mat is None:
mat = col
else:
mat = hstack((mat, col))
Whereas if it were a list, I'd do something like this:
list = []
for item in data:
list.append(item)
Is there a way to use that kind of notation for NumPy arrays or matrices? (Or a better way -- I'm still pretty new to python!)
© Stack Overflow or respective owner