Heisenberg
Heisenberg

Reputation: 21

initialize matrix with vectors Python

I want to initialize a Matrix with 3 vectors. The special part about is that I want the vectors to be the columns the matrix.

Vx= np.zeros((npoints,))
Vy=np.zeros((npoints,))
Vz=np.zeros((npoints,))
V=np.matrix(([Vx,Vy,Vz]))

Now the problem here is that the vectors form the rows of the matrix. How can I fix that?

Upvotes: 0

Views: 230

Answers (3)

Eric
Eric

Reputation: 97691

There's a shorthand in numpy for this:

V = np.c_[Vx, Vy, Vz]

Upvotes: 1

titipata
titipata

Reputation: 5389

An alternative for unutbu solution is to use np.vstack or np.hstack

V = np.matrix(np.vstack((Vx, Vy, Vz)).T)

Upvotes: 0

unutbu
unutbu

Reputation: 880807

You could use np.column_stack:

V = np.column_stack([Vx, Vy, Vz])

Upvotes: 1

Related Questions