# Transposed matrix

**URL:** <https://discourse.julialang.org/t/transposed-matrix/76597>\
**Category:** New to Julia\
**Tags:** linearalgebra\
**Created:** [February 17, 2022, 1:14am UTC](https://discourse.julialang.org/t/transposed-matrix/76597 "2022-02-17T01:14:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lln](https://avatars.discourse-cdn.com/v4/letter/l/ecae2f/32.png) [@lln](https://discourse.julialang.org/u/lln)\
**Post date:** [February 17, 2022, 1:14am UTC](https://discourse.julialang.org/t/transposed-matrix/76597/1 "2022-02-17T01:14:06Z")

</div>

Hi,

I’m new to Julia and I apologize in advance if there’s a simple answer to my question somewhere but I’ve spent lots of time without any success.

I’m trying to re-write the following Python code in Julia

```julia
import scipy as sp
psi = sp.ones((1000, 1))
idx_blk = range(15)
x = sp.diag(1.0/psi[idx_blk].T[0])

```

My problem is I don’t know exactly what the `[0]` in the code above is doing (more of a Python issue but was hoping someone here might have a solution).

Julia

```julia
using LinearAlgebra
psi = ones(1000, 1)
idx_blk = 1:15
x = Diagonal(1.0 ./ transpose(psi[idx_blk]))

```

Thanks!

---

<div class="post-metadata">

**Author:** ![jd-foster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jd-foster/32/35824_2.png) [@jd-foster](https://discourse.julialang.org/u/jd-foster)\
**Post date:** [February 17, 2022, 2:32am UTC](https://discourse.julialang.org/t/transposed-matrix/76597/2 "2022-02-17T02:32:31Z")

</div>

```python
>>> psi[idx_blk].T
array([[1., 1., 1., 1., 1.]])

```

Notice the double brackets `[[`, compared to

```python
>>> psi[idx_blk].T[0]
array([1., 1., 1., 1., 1.])

```

so the `[0]` is pulling out the first array from an “array-of-arrays” (a type of matrix?).

To get the same result in Julia you can do this:

```julia
using LinearAlgebra
psi = ones(10, 1)
idx_blk = 1:5
x = diagm(1.0./psi[idx_blk])

```

Note I’ve reduced the numbers. You don’t need to use `transpose` either.
