In [1]:
import numpy as np
In [2]:
a_2d = np.arange(12).reshape(3, 4)
print(a_2d)
In [3]:
print(a_2d[1, 1:3])
In [4]:
print(a_2d[1, [False, True, True, False]])
In [5]:
print(a_2d[1, [1, 2]])
In [6]:
print(a_2d[1:3, 1:3])
In [7]:
print(a_2d[1:3, [False, True, True, False]])
In [8]:
print(a_2d[1:3, [1, 2]])
In [9]:
print(a_2d[np.ix_([1, 2], [False, True, True, False])])
In [10]:
a_3d = np.arange(24).reshape(2, 3, 4)
print(a_3d)
In [11]:
print(a_3d[:, :2, [True, False, True, False]])
In [12]:
print(a_3d[:, :2, [0, 2]])
In [13]:
print(a_3d[:, [0, 2], [0, 2]])
In [14]:
# print(a_3d[np.ix_(:, [0, 2], [0, 2])])
# SyntaxError: invalid syntax
In [15]:
print(a_3d[np.ix_(range(2), [0, 2], [0, 2])])
In [16]:
print(a_3d[np.ix_(range(a_3d.shape[0]), [0, 2], [0, 2])])
In [17]:
# print(a_3d[np.ix_(0, [0, 2], [0, 2])])
# ValueError: Cross index must be 1 dimensional
In [18]:
print(a_3d[np.ix_([0], [0, 2], [0, 2])])