Matrice with many elements

This is the place for queries that don't fit in any of the other categories.

Matrice with many elements

Postby Cereal » Wed Apr 16, 2014 6:55 pm

Hi everybody!

I want to code a matrix, which I don't know the number of elements of.

The matrix looks like this:

Code: Select all
 xo^N   xo^(N-1)     xo^(N-2)     ...    xo^1     xo^0
 xo^N   xo^(N-1)     xo^(N-2)     ...    xo^1     xo^0
...                                           ...                ...
...                                           ...                ...
 xn^N   xn^(N-1)     xn^(N-2)     ...    xn^1     xn^0


where n=N.

I know how to create a matrix but it makes me confused that it is unlimited.

I was thinking about doing this with for loop, but I don't know exactly how.

I want to write it exactly like here with a lot of dots, but I can't ;)

I started even if I didn't know how to, and wrote this:

Code: Select all
def v(x0,x1,x2,x3,x4,N):
       v1 = [array((x0,x1,x2,x3,x4))]
       return ve0 = (array(v1**(N)))
                ve1 = (array(v1**(N-1)))
               ve2 = (array(v1**(N-1)))

               vei = (array(v1**(N-i))for i in xrange(0,N))

return column stack([v1, v2, v3, v4, v5]).


But I do realize that I have to do it differently.

Could someone please help me?

Thank you!
// Luce.
Last edited by stranac on Wed Apr 16, 2014 8:31 pm, edited 1 time in total.
Cereal
 
Posts: 15
Joined: Tue Apr 15, 2014 7:42 am

Re: Matrice with many elements

Postby micseydel » Wed Apr 16, 2014 8:32 pm

I don't understand what you want here. Could you describe some example input and output? Input could be a nested list or tuple, and your output could be a Python data structure as well, or something from numpy or whatever you're using (whatever that is, you need to tell us).
Join the #python-forum IRC channel on irc.freenode.net!
User avatar
micseydel
 
Posts: 1128
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Matrice with many elements

Postby Cereal » Thu Apr 17, 2014 8:11 pm

Hi!

This is an exercise. It says that I will make a matrix with not known number of elements. When this is done I will continue with the matrix in other exercises.

I am thinking something like this: write the matrix without specify the number of elements, vectors, and write the number somewhere else, so I can change easily. Maybe like arguments and have this written like a function. Is this possible?

I have Python, Spyder and Numpy installed, but I write "Spider" on the "black board" before programming. Is it Spyder then? (Sorry, I'm a beginner).


The "code" I printed before was the matrix that I am thinking of.

I will try to give an example.



So far, I wrote following:

Code: Select all
v = array([1,2,3,5,7,8])
N = 7
m1 = ([v**N])
m2 = ([v**(N-1)])
m3 = ([v**(N-2)])
m4 = ([v**(N-3)])
m5 = ([v**(N-4)])
m6 = ([v**(N-5)])
m7 = ([v**(N-6)])
m8 = ([v**(N-7)])


print column_stack(([m1],[m2],[m3],[m4],[m5],[m6],[m7],[m8]))
,

and this is a certain number of elements. But I want matrix column to be "v^(N-i), with N NOT fixed, so I could print N=7 or N=8 or N=21 afterwards and change it. I also want to change the number of mi:s. Is this possible? Will I use for loops? How do I do?

Thanks! :)

// Luce.
Cereal
 
Posts: 15
Joined: Tue Apr 15, 2014 7:42 am

Re: Matrice with many elements

Postby micseydel » Thu Apr 17, 2014 10:01 pm

Code: Select all
column_stack([[[v**n]] for n in xrange(N, -1, -1)])
Join the #python-forum IRC channel on irc.freenode.net!
User avatar
micseydel
 
Posts: 1128
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Matrice with many elements

Postby Marbelous » Thu Apr 17, 2014 10:12 pm

Python is the language itself. Spyder is an IDE (an Integrated Development Environment where you can write code, debug and execute within the same program for convenience). Numpy is a python module that adds advanced math functions and abilities (including matrices) to python.

If you want to add matrix functionality to python in a way that you can use it for your own purposes you need a DEEP understanding of python so that you can override the methods of it's built-in classes.

Since Numpy already does this for you it's silly to reproduce but if you want to modify the numpy.matrix class to suit your own purposes or just want to study it I suggest you start there. See the basic docs at Scipy.org first: http://docs.scipy.org/doc/numpy/referen ... atrix.html
Marbelous
 
Posts: 97
Joined: Fri May 31, 2013 8:12 pm


Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 2 guests