1

I have two "matrix" [X] = [X1,X2,...,Xn] and [T](Xi) = [Ti1,Ti2,...,Tim] with Xi and Tij are reals numbers. Xi describe the position of point X (one dimensional), [T](Xi) describe the velocity of Xi.

I want to create a double array A in Python so: A=A[Xi][Tj].

By example:

A[0][i] = [T](X1) = T1j = [T11,T12,...,T1m]

and

A[1][i] = [T](X2) = T2j = [T21,T22,...,T2m]

I tried:

tableA = [X,T]

but that does not work well.

hopper
  • 13,060
  • 7
  • 49
  • 53
user2863620
  • 635
  • 3
  • 10
  • 17
  • 1
    Ca you add a short example of your expected inputs and desired output? Preferably as executable Python code. i.e. `X = [0, 1, 2, 3]` – YXD Oct 09 '13 at 16:07
  • Could you add the dimensions of X, T and A? I suppose that X is (nx1) that A is (nx?), but I don't get the dimension of T. – Noctua Oct 09 '13 at 16:12
  • Do you have a list of T for each point in X? Then it looks like you just need a dict(). Are m,n fixed? An alternative would be a list of lists. – dornhege Oct 09 '13 at 16:14
  • By example X=[0,2,4,6,8] (so X is matrix 1x5) T(X=0) = [1,2,3,4] T(X=2) = [1,2,3,4] ... So A=[X][T], A(X=0)[0] = T(X=0)[0] = 1 – user2863620 Oct 09 '13 at 18:37

2 Answers2

0

Forgive me, because I'm not sure I fully understood your question - but the gist I'm getting is you essentially want a two dimensional array in Python? Then this question will help:

How to define two-dimensional array in python

Community
  • 1
  • 1
davecom
  • 1,499
  • 10
  • 30
  • Please post this sort of thing as a comment, not an answer. In fact, if you believe that the question is a duplicate of the one you've linked to, please feel free to flag it as a duplicate, which will direct future visitors to the previous question. – askewchan Oct 09 '13 at 16:37
0

Your question is quite hard to understand, but I take it you want a matrix A, where the rows of A correspond to the T vectors?

That, you can create like this:

x_vector = [x1, x2, x3, x4, x5, ...]
a_matrix = [t_matrix(X[i]) for i in range(len(X))]

Then, you'll see that

>>> a_matrix[0][:]
[t11, t12, t13, ..., t1m]
>>> a_matrix[1][:]
[t21, t22, t23, ..., t2m]

if t_matrix is a matrix where the xi'th row is the velocity vector for xi. Now a_matrix will be a matrix where the ith row is the velocity vector for xi.

Noctua
  • 5,058
  • 1
  • 18
  • 23