您可以使用元组索引:
>>> import numpy as np>>> a = np.zeros((4,2))>>> vals = [4,3,2,1]>>> pos = [(0,0),(1,1),(2,0),(3,1)]>>> rows, cols = zip(*pos)>>> a[rows, cols] = vals>>> aarray([[ 4., 0.], [ 0., 3.], [ 2., 0.], [ 0., 1.]])
欢迎分享,转载请注明来源:内存溢出
您可以使用元组索引:
>>> import numpy as np>>> a = np.zeros((4,2))>>> vals = [4,3,2,1]>>> pos = [(0,0),(1,1),(2,0),(3,1)]>>> rows, cols = zip(*pos)>>> a[rows, cols] = vals>>> aarray([[ 4., 0.], [ 0., 3.], [ 2., 0.], [ 0., 1.]])
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)