import numpy as np

a = np.arange(10) * 10
print(a)
# [ 0 10 20 30 40 50 60 70 80 90]

print(a[5])
# 50

print(a[8])
# 80

print(a[[5, 8]])
# [50 80]

print(a[[5, 4, 8, 0]])
# [50 40 80  0]

print(a[[5, 5, 5, 5]])
# [50 50 50 50]

idx = np.array([[5, 4], [8, 0]])
print(idx)
# [[5 4]
#  [8 0]]

print(a[idx])
# [[50 40]
#  [80  0]]

# print(a[[[5, 4], [8, 0]]])
# IndexError: too many indices for array

print(a[[[[5, 4], [8, 0]]]])
# [[50 40]
#  [80  0]]

a_2d = np.arange(12).reshape((3, 4))
print(a_2d)
# [[ 0  1  2  3]
#  [ 4  5  6  7]
#  [ 8  9 10 11]]

print(a_2d[0])
# [0 1 2 3]

print(a_2d[2])
# [ 8  9 10 11]

print(a_2d[[2, 0]])
# [[ 8  9 10 11]
#  [ 0  1  2  3]]

print(a_2d[[2, 2, 2]])
# [[ 8  9 10 11]
#  [ 8  9 10 11]
#  [ 8  9 10 11]]

print(a_2d[:, 1])
# [1 5 9]

print(a_2d[:, 3])
# [ 3  7 11]

print(a_2d[:, 1:2])
# [[1]
#  [5]
#  [9]]

print(a_2d[:, [3, 1]])
# [[ 3  1]
#  [ 7  5]
#  [11  9]]

print(a_2d[:, [3, 3, 3]])
# [[ 3  3  3]
#  [ 7  7  7]
#  [11 11 11]]

print(a_2d[0, 1])
# 1

print(a_2d[2, 3])
# 11

print(a_2d[[0, 2], [1, 3]])
# [ 1 11]

# index
# [[0, 1] [2, 3]]

# print(a_2d[[0, 2, 1], [1, 3]])
# IndexError: shape mismatch: indexing arrays could not be broadcast together with shapes (3,) (2,) 

print(a_2d[[[0, 0], [2, 2]], [[1, 3], [1, 3]]])
# [[ 1  3]
#  [ 9 11]]

# index
# [[0, 1] [0, 3]
#  [2, 1] [2, 3]]

print(a_2d[[[0], [2]], [1, 3]])
# [[ 1  3]
#  [ 9 11]]

idxs = np.ix_([0, 2], [1, 3])
print(idxs)
# (array([[0],
#        [2]]), array([[1, 3]]))

print(type(idxs))
# <class 'tuple'>

print(type(idxs[0]))
# <class 'numpy.ndarray'>

print(idxs[0])
# [[0]
#  [2]]

print(idxs[1])
# [[1 3]]

print(a_2d[np.ix_([0, 2], [1, 3])])
# [[ 1  3]
#  [ 9 11]]

print(a_2d[np.ix_([2, 0], [3, 3, 3])])
# [[11 11 11]
#  [ 3  3  3]]

print(a_2d[[0, 2]][:, [1, 3]])
# [[ 1  3]
#  [ 9 11]]

a_2d = np.arange(12).reshape((3, 4))
print(a_2d)
# [[ 0  1  2  3]
#  [ 4  5  6  7]
#  [ 8  9 10 11]]

a_2d[np.ix_([0, 2], [1, 3])] = 100
print(a_2d)
# [[  0 100   2 100]
#  [  4   5   6   7]
#  [  8 100  10 100]]

a_2d[np.ix_([0, 2], [1, 3])] = [100, 200]
print(a_2d)
# [[  0 100   2 200]
#  [  4   5   6   7]
#  [  8 100  10 200]]

a_2d[np.ix_([0, 2], [1, 3])] = [[100, 200], [300, 400]]
print(a_2d)
# [[  0 100   2 200]
#  [  4   5   6   7]
#  [  8 300  10 400]]

print(a_2d[[0, 2]][:, [1, 3]])
# [[100 200]
#  [300 400]]

a_2d[[0, 2]][:, [1, 3]] = 0
print(a_2d)
# [[  0 100   2 200]
#  [  4   5   6   7]
#  [  8 300  10 400]]

a_2d = np.arange(12).reshape((3, 4))
print(a_2d)
# [[ 0  1  2  3]
#  [ 4  5  6  7]
#  [ 8  9 10 11]]

a_2d[[2, 0]] = [[100, 200, 300, 400], [500, 600, 700, 800]]
print(a_2d)
# [[500 600 700 800]
#  [  4   5   6   7]
#  [100 200 300 400]]

a_2d[[2, 2]] = [[-1, -2, -3, -4], [-5, -6, -7, -8]]
print(a_2d)
# [[500 600 700 800]
#  [  4   5   6   7]
#  [ -5  -6  -7  -8]]

a_2d = np.arange(12).reshape((3, 4))
print(a_2d)
# [[ 0  1  2  3]
#  [ 4  5  6  7]
#  [ 8  9 10 11]]

a_fancy = a_2d[np.ix_([0, 2], [1, 3])]
print(a_fancy)
# [[ 1  3]
#  [ 9 11]]

a_fancy[0, 0] = 100
print(a_fancy)
# [[100   3]
#  [  9  11]]

print(a_2d)
# [[ 0  1  2  3]
#  [ 4  5  6  7]
#  [ 8  9 10 11]]

a_2d = np.arange(12).reshape((3, 4))
print(a_2d)
# [[ 0  1  2  3]
#  [ 4  5  6  7]
#  [ 8  9 10 11]]

print(a_2d[[2, 0], ::-1])
# [[11 10  9  8]
#  [ 3  2  1  0]]

print(a_2d[::2, [3, 0, 1]])
# [[ 3  0  1]
#  [11  8  9]]

import numpy as np

a = np.arange(10) * 10
print(a)
# [ 0 10 20 30 40 50 60 70 80 90]

print(a[5])
# 50

print(a[8])
# 80

print(a[[5, 8]])
# [50 80]

print(a[[5, 4, 8, 0]])
# [50 40 80  0]

print(a[[5, 5, 5, 5]])
# [50 50 50 50]

idx = np.array([[5, 4], [8, 0]])
print(idx)
# [[5 4]
#  [8 0]]

print(a[idx])
# [[50 40]
#  [80  0]]

# print(a[[[5, 4], [8, 0]]])
# IndexError: too many indices for array

print(a[[[[5, 4], [8, 0]]]])
# [[50 40]
#  [80  0]]

a_2d = np.arange(12).reshape((3, 4))
print(a_2d)
# [[ 0  1  2  3]
#  [ 4  5  6  7]
#  [ 8  9 10 11]]

print(a_2d[0])
# [0 1 2 3]

print(a_2d[2])
# [ 8  9 10 11]

print(a_2d[[2, 0]])
# [[ 8  9 10 11]
#  [ 0  1  2  3]]

print(a_2d[[2, 2, 2]])
# [[ 8  9 10 11]
#  [ 8  9 10 11]
#  [ 8  9 10 11]]

print(a_2d[:, 1])
# [1 5 9]

print(a_2d[:, 3])
# [ 3  7 11]

print(a_2d[:, 1:2])
# [[1]
#  [5]
#  [9]]

print(a_2d[:, [3, 1]])
# [[ 3  1]
#  [ 7  5]
#  [11  9]]

print(a_2d[:, [3, 3, 3]])
# [[ 3  3  3]
#  [ 7  7  7]
#  [11 11 11]]

print(a_2d[0, 1])
# 1

print(a_2d[2, 3])
# 11

print(a_2d[[0, 2], [1, 3]])
# [ 1 11]

# index
# [[0, 1] [2, 3]]

# print(a_2d[[0, 2, 1], [1, 3]])
# IndexError: shape mismatch: indexing arrays could not be broadcast together with shapes (3,) (2,) 

print(a_2d[[[0, 0], [2, 2]], [[1, 3], [1, 3]]])
# [[ 1  3]
#  [ 9 11]]

# index
# [[0, 1] [0, 3]
#  [2, 1] [2, 3]]

print(a_2d[[[0], [2]], [1, 3]])
# [[ 1  3]
#  [ 9 11]]

idxs = np.ix_([0, 2], [1, 3])
print(idxs)
# (array([[0],
#        [2]]), array([[1, 3]]))

print(type(idxs))
# <class 'tuple'>

print(type(idxs[0]))
# <class 'numpy.ndarray'>

print(idxs[0])
# [[0]
#  [2]]

print(idxs[1])
# [[1 3]]

print(a_2d[np.ix_([0, 2], [1, 3])])
# [[ 1  3]
#  [ 9 11]]

print(a_2d[np.ix_([2, 0], [3, 3, 3])])
# [[11 11 11]
#  [ 3  3  3]]

print(a_2d[[0, 2]][:, [1, 3]])
# [[ 1  3]
#  [ 9 11]]

a_2d = np.arange(12).reshape((3, 4))
print(a_2d)
# [[ 0  1  2  3]
#  [ 4  5  6  7]
#  [ 8  9 10 11]]

a_2d[np.ix_([0, 2], [1, 3])] = 100
print(a_2d)
# [[  0 100   2 100]
#  [  4   5   6   7]
#  [  8 100  10 100]]

a_2d[np.ix_([0, 2], [1, 3])] = [100, 200]
print(a_2d)
# [[  0 100   2 200]
#  [  4   5   6   7]
#  [  8 100  10 200]]

a_2d[np.ix_([0, 2], [1, 3])] = [[100, 200], [300, 400]]
print(a_2d)
# [[  0 100   2 200]
#  [  4   5   6   7]
#  [  8 300  10 400]]

print(a_2d[[0, 2]][:, [1, 3]])
# [[100 200]
#  [300 400]]

a_2d[[0, 2]][:, [1, 3]] = 0
print(a_2d)
# [[  0 100   2 200]
#  [  4   5   6   7]
#  [  8 300  10 400]]

a_2d = np.arange(12).reshape((3, 4))
print(a_2d)
# [[ 0  1  2  3]
#  [ 4  5  6  7]
#  [ 8  9 10 11]]

a_2d[[2, 0]] = [[100, 200, 300, 400], [500, 600, 700, 800]]
print(a_2d)
# [[500 600 700 800]
#  [  4   5   6   7]
#  [100 200 300 400]]

a_2d[[2, 2]] = [[-1, -2, -3, -4], [-5, -6, -7, -8]]
print(a_2d)
# [[500 600 700 800]
#  [  4   5   6   7]
#  [ -5  -6  -7  -8]]

a_2d = np.arange(12).reshape((3, 4))
print(a_2d)
# [[ 0  1  2  3]
#  [ 4  5  6  7]
#  [ 8  9 10 11]]

a_fancy = a_2d[np.ix_([0, 2], [1, 3])]
print(a_fancy)
# [[ 1  3]
#  [ 9 11]]

a_fancy[0, 0] = 100
print(a_fancy)
# [[100   3]
#  [  9  11]]

print(a_2d)
# [[ 0  1  2  3]
#  [ 4  5  6  7]
#  [ 8  9 10 11]]

a_2d = np.arange(12).reshape((3, 4))
print(a_2d)
# [[ 0  1  2  3]
#  [ 4  5  6  7]
#  [ 8  9 10 11]]

print(a_2d[[2, 0], ::-1])
# [[11 10  9  8]
#  [ 3  2  1  0]]

print(a_2d[::2, [3, 0, 1]])
# [[ 3  0  1]
#  [11  8  9]]

# [ 0 10 20 30 40 50 60 70 80 90] # 50 # 80 # [50 80] # [50 40 80  0] # [50 50 50 50] # [[5 4] #  [8 0]] # [[50 40] #  [80  0]] # print(a[[[5, 4], [8, 0]]]) # IndexError: too many indices for array # [[50 40] #  [80  0]] # [[ 0  1  2  3] #  [ 4  5  6  7] #  [ 8  9 10 11]] # [0 1 2 3] # [ 8  9 10 11] # [[ 8  9 10 11] #  [ 0  1  2  3]] # [[ 8  9 10 11] #  [ 8  9 10 11] #  [ 8  9 10 11]] # [1 5 9] # [ 3  7 11] # [[1] #  [5] #  [9]] # [[ 3  1] #  [ 7  5] #  [11  9]] # [[ 3  3  3] #  [ 7  7  7] #  [11 11 11]] # 1 # 11 # [ 1 11] # index # [[0, 1] [2, 3]] # print(a_2d[[0, 2, 1], [1, 3]]) # IndexError: shape mismatch: indexing arrays could not be broadcast together with shapes (3,) (2,) # [[ 1  3] #  [ 9 11]] # index # [[0, 1] [0, 3] #  [2, 1] [2, 3]] # [[ 1  3] #  [ 9 11]] # (array([[0], #        [2]]), array([[1, 3]])) # <class 'tuple'> # <class 'numpy.ndarray'> # [[0] #  [2]] # [[1 3]] # [[ 1  3] #  [ 9 11]] # [[11 11 11] #  [ 3  3  3]] # [[ 1  3] #  [ 9 11]] # [[ 0  1  2  3] #  [ 4  5  6  7] #  [ 8  9 10 11]] # [[  0 100   2 100] #  [  4   5   6   7] #  [  8 100  10 100]] # [[  0 100   2 200] #  [  4   5   6   7] #  [  8 100  10 200]] # [[  0 100   2 200] #  [  4   5   6   7] #  [  8 300  10 400]] # [[100 200] #  [300 400]] # [[  0 100   2 200] #  [  4   5   6   7] #  [  8 300  10 400]] # [[ 0  1  2  3] #  [ 4  5  6  7] #  [ 8  9 10 11]] # [[500 600 700 800] #  [  4   5   6   7] #  [100 200 300 400]] # [[500 600 700 800] #  [  4   5   6   7] #  [ -5  -6  -7  -8]] # [[ 0  1  2  3] #  [ 4  5  6  7] #  [ 8  9 10 11]] # [[ 1  3] #  [ 9 11]] # [[100   3] #  [  9  11]] # [[ 0  1  2  3] #  [ 4  5  6  7] #  [ 8  9 10 11]] # [[ 0  1  2  3] #  [ 4  5  6  7] #  [ 8  9 10 11]] # [[11 10  9  8] #  [ 3  2  1  0]] # [[ 3  0  1] #  [11  8  9]]