[numpy]索引问题(np.ix_()用法)

import numpy as np
x = np.arange(12).reshape(4,3)
x
>>>array([[ 0,  1,  2],
       [ 3,  4,  5],
       [ 6,  7,  8],
       [ 9, 10, 11]])
rows = np.array([0,3])
cols = np.array([0,2])

# 一
x[rows,cols]
>>>array([ 0, 11])

# 二
a, b = np.meshgrid(rows, cols)
x[a,b]
>>>array([[ 0,  9],
       [ 2, 11]])

# 三
x[np.ix_(rows,cols)]
>>>array([[ 0,  2],
       [ 9, 11]])

你可能感兴趣的:(numpy,python,numpy)