1、fromfunction
def f(x,y): ... return 10*x+y ... >>> b = np.fromfunction(f,(5,4),dtype=int) >>> b array([[ 0, 1, 2, 3], [10, 11, 12, 13], [20, 21, 22, 23], [30, 31, 32, 33], [40, 41, 42, 43]])
f(x,y)中x和y分别指,5*4矩阵对应的x下标和y下标。例如第一个元素下标是0,0.带入f(x,y)中,返回的值是10*0+0=0.