# My matrix from a list is being built incorrect

Hi,

I dont get what is going on here. One would think I would get an off diag.

``````let mut XI_matrix = DMatrix::from_iterator(xi_rows,xi_cols,xi_weights.iter().cloned());
println!("XI_matrix: {}",XI_matrix);
``````

xi_weights: [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0]
XI_matrix:
┌ ┐
│ 1 1 1 1 1 1 1 1 │
│ 0 0 0 0 0 0 0 0 │
│ 0 0 0 0 0 0 0 0 │
│ 0 0 0 0 0 0 0 0 │
│ 1 1 1 1 1 1 1 1 │
│ 0 0 0 0 0 0 0 0 │
│ 0 0 0 0 0 0 0 0 │
│ 0 0 0 0 0 0 0 0 │
└ ┘

Hi,

One would think I would get an off diag.

Not sure I understand. Could you write down the matrix you’d expect to get here?

Below is what I am expecting

1 0 0 0 1 0 0 0
0 1 0 0 0 1 0 0
0 0 1 0 0 0 1 0
. . .

Perhaps your `xi_rows` was wrong? You seem to need 3 rows while your first example had 8.
Or if you actually needed 8 rows, then your xi_weights should look like this:

``````[ 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,   0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, ... ]
``````

because matrix elements must be provided in column-major order (i.e. column-by-column).