Python access all entrys from one dimension in a multidimensional numpy array
<p>I would like to manipulate the data of all entries of a complicated 3d numpy array. I want all entries of all subarrays in the X-Y-Position. I know Matlab can do something like that (with the variable indicator : for everything) I indicated that below with DARK[:][1][1]. Which basically mean I want the second entry from the second the column in all sub arrays. Is there a way to do this in python?</p>

<pre><code>import numpy

# Creating a dummy variable of the type I deal with (If this looks crappy sorry, the variable actually comes from the output of d = pyfits.getdata()):
a = []
for i in range(3):
    d = numpy.array([[i, 2*i], [3*i, 4*i]])
    a.append(d)

print a
# Pseudo code:
print 'Second row, second column: ', a[:][1][1]
</code></pre>

<p>I expect a result like this:</p>

<pre><code>[array([[ 0,  0],[ 0,  0]]),
array([[ 1,  2],[ 3,  4]]),
array([[ 2,  4],[ 6,  8]])]

Second row, second column: [0, 4, 8]
</code></pre>

<p>The point is you are creating a list of arrays, not a multidimensional array. For this specific example you can use <a href="https://docs.python.org/2/tutorial/datastructures.html#list-comprehensions" rel="nofollow">list comprehensions</a> to build directly the structure you need and convert it to an array. Then you can access the elements you need using a somewhat matlab-like syntax:</p>

<pre><code>import numpy as np

d = np.array([[[i, 2*i], [3*i, 4*i]] for i in range(3) ])
print("Second Row, Second Column: ", d[:,1,1])
</code></pre>

python arrays numpy