How can I store a result in a Matrix?

Ben Champion ben.champion at gmail.com
Fri Nov 19 20:41:43 CET 2004


I am new to Python so please excuse me if this sounds simple! Before I
explain what i want to do let me write some code in matlab which
demonstrates what I would like to acheive, using the Fibonnachi series
as an example:


a = 1
b = 1
for i = 1:10
z = a + b
a = b
b = z
y(i) = z
end

This gives me the variable y with values 
2    3    5     8    13    21    34    55    89   144

which is essentially a matrix which i can plot against another matrix
xof the same dimensions

In python I have

a = 1
b = 1
for i in range(1, 11)
    z = a + b
    a = b
    b = z
    
which gives me all the values I need, but i do not know how to store
the values of z in a single matrix. I have looked at several online
resources and played about with the array commands but cant get it to
work. If someone could point me to a relevant webpage or suggest code
that will work I would be very grateful

Thanks

Ben



More information about the Python-list mailing list