I am just moving into python3 from MATLAB. So my question may be silly, although I looked into the issue intensively but could not find a solution to my problem. So here is my problem - I have created a 3d array list using
routine_matrix = [[[0 for k in range(xaxis)] for j in range(yaxis)] for i in range(zaxis)]
routine_matrix[0][0][1] = 'aa'
routine_matrix[1][0][1] = 'bb'
routine_matrix[2][0][1] = 'cc'
routine_matrix[3][0][1] = 'dd'
routine_matrix[4][0][1] = 'ee'
routine_matrix[0][1][1] = 'ff'
routine_matrix[0][2][1] = 'gg'
And this is how the 3d list look like:
[[[0, 'aa', 0, 0], [0, 'ff', 0, 0], [0, 'gg', 0, 0]],
[[0, 'bb', 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]],
[[0, 'cc', 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]],
[[0, 'dd', 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]],
[[0, 'ee', 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]]
Now if I want to access the elements 'aa', 'bb', 'cc', 'dd' and 'ee', using for loop I can easily do that using the following code:
for i in range(0,5):
print(routine_matrix[i][0][1])
However, what I want to do is, I want to slice from the 3d list at one shot - something like:
print(routine_matrix[0:,0,1])
However, I am not getting my desired output. So all I am asking is how can I slice off 'aa', 'bb', 'cc', 'dd' and 'ee' at one go.
Thanks for your time!
numpyinstalled and tried using numpy arrays? They support the slicing you're after... (and using syntax like the one you're trying to do currently on normal Python lists)numpy?