DrakonianD - 11 months ago 34

Python Question

I have a problem with printing a column in a numpy 3D Matrix.

Here is a simplified version of the problem:

`import numpy as np`

Matrix = np.zeros(((10,9,3))) # Creates a 10 x 9 x 3 3D matrix

Matrix[2][2][6] = 578

# I want to print Matrix[2][x][6] for x in range(9)

# the purpose of this is that I want to get all the Values in Matrix[2][x][6]

Much appreciated if you guys can help me out.

Thanks in advance.

Answer

Not sure if Numpy supports this, but you can do it with normal lists this way:

If you have three lists `a = [1,2,3]`

, `b = [4,5,6]`

, and `c = [7,8,9]`

, you can get the second dimension `[2,5,8]`

for example by doing

```
list(zip(a,b,c))[1]
```

EDIT:

Turns out this is pretty simple in Numpy. According to this thread you can just do:

```
Matrix[:,1]
```