Loading [MathJax]/jax/output/HTML-CSS/jax.js

First time here? Check out the FAQ!

Ask Your Question
0

Unflatten a vector

asked 6 years ago

abel gravatar image

updated 5 years ago

slelievre gravatar image

I have a vector say a 9×1 vector which looks like [2x+1x1xx2+2x2xx2x20] with entries in F3[x].

There are 9 rows in this matrix and i want to write a function which takes an n2×1 matrix and turns it into a n×n matrix. So, in this case, we want the function would turn the above vector into

[2x+1x1xx2+2x2xx2x20]

In this Sage, I tried this:

sage: v = Matrix(GF(3)[x], [[2*x+1],[x],[1],[x],[x^2+2*x],[2*x],[x],[2*x^2],[0]])

Then, write the following:

sage: Matrix(v.base_ring(), 3, 3, v)

This gave an error:

inconsistent number of rows: should be 3 but got 1
Preview: (hide)

2 Answers

Sort by » oldest newest most voted
2

answered 5 years ago

Another option: if v is a matrix of any shape with 32 entries, then v.list() will list those entries. So then you can do matrix(3, 3, v.list()) to turn v into a 3 by 3 matrix.

Preview: (hide)
link

Comments

and take the transpose then. that works.

abel gravatar imageabel ( 5 years ago )
1

answered 6 years ago

rburing gravatar image

updated 6 years ago

You can do the following if v is a 32×1 matrix (as in your example):

Matrix([vector(v[3*k:3*k+3,0].transpose()) for k in range(3)])

Or more easily, if v is a vector with 32 components:

v = vector(GF(3)[x], [2*x+1,x,1,x,x^2+2*x,2*x,x,2*x^2,0])
Matrix([v[3*k:3*k+3] for k in range(3)])
Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 6 years ago

Seen: 784 times

Last updated: Apr 11 '19