Python函数--numpy.fromfunction( )

来源:互联网 发布:linux qt开发环境搭建 编辑:程序博客网 时间:2024/06/08 06:16

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 npdef f(x,y):    return 10*x+yb=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]]
原创粉丝点击