np.fromfunction( )
库numpy中的函数fromfunction(function,shape,dtype ):
(1)function
def function(x,y):
函数内部
(x,y)分别是以左上角为原点的坐标,x为行坐标,y为列坐标,表示第x行y列。
(2)shape:(a,b)
表示数组array的大小,a行b列。
(3)dtype:
表示数组的数类型
Example:
import numpy as np
def f(x,y):
return 10*x+y
b=np.fromfunction(f,(5,4),dtype=int)
print b
输出结果:
[[ 0 1 2 3]
[10 11 12 13]
[20 21 22 23]
[30 31 32 33]
[40 41 42 43]]