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>You can do this using slightly different syntax.</p>

<pre><code>import numpy as np

a = np.arange(27).reshape(3,3,3) # Create a 3x3x3 3d array

print("3d Array:")
print(a)
print("Second Row, Second Column: ", a[:,1,1])
</code></pre>

<p>Output:</p>

<pre><code>&gt;&gt;&gt; 3d Array:
 [[[ 0  1  2]
   [ 3  4  5]
   [ 6  7  8]]

  [[ 9 10 11]
   [12 13 14]
   [15 16 17]]

  [[18 19 20]
   [21 22 23]
   [24 25 26]]]

&gt;&gt;&gt; Second Row, Second Column:  [ 4 13 22]
</code></pre>

python arrays numpy