Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TugboatEng on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Python and arrays

Status
Not open for further replies.

barney75

Mechanical
Joined
Jan 22, 2007
Messages
58
Location
IT
Hy guys,
I need an help on how to manipulate arrays in python using the module Numeric or array.
Consider the following array a

a = reshape(arange(9),(3,3))
>>> print a
[[0 1 2]
[3 4 5]
[6 7 8]]

ok, now how is it possible (any command?) to add a new row let say [9,10,11] to the array a in order to get a new matrix a as follows:

[[0 1 2]
[3 4 5]
[6 7 8]
[9 10 11]]

I need to know it in order to assemble a matrix recursively inside a loop.

Thanks bye
 
I think it should just be:

a.append([9,10,11])

HTH
Dan
 
Hi DanStro
thanks for your advice, but it doesn't work. As far as I know the append method is available in array module. I've imported the array module and tried your solution but it seems that a.append() require a float as input in brackets therefore u can not give [9,10,11]. As said previously I need to assemble an array in a loop in order to use slicing methods.

Any other advice will be appreciate.

Bye

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top