Matrice with many elements

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

Matrice with many elements

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.

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

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).
Due to the reasons discussed here we will be moving to python-forum.io on October 1, 2016.

This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.

micseydel

Posts: 3000
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Matrice with many elements

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 = 7m1 = ([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

Code: Select all
`column_stack([[[v**n]] for n in xrange(N, -1, -1)])`
Due to the reasons discussed here we will be moving to python-forum.io on October 1, 2016.

This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.

micseydel

Posts: 3000
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Matrice with many elements

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: 401
Joined: Fri May 31, 2013 8:12 pm