📜  numpy.fromfunction()函数Python

📅  最后修改于: 2022-05-13 01:55:45.299000             🧑  作者: Mango

numpy.fromfunction()函数Python

numpy.fromfunction()函数通过在每个坐标上执行一个函数来构造一个数组,因此,结果数组在坐标 (x, y, z) 处具有值 fn(x, y, z)。

代码#1:

Python3
# Python program explaining
# numpy.fromfunction() function
    
# importing numpy as geek
import numpy as geek
    
gfg = geek.fromfunction(lambda i, j: i * j, (4, 4), dtype = float)
    
print(gfg)


Python3
# Python program explaining
# numpy.fromfunction() function
    
# importing numpy as geek
import numpy as geek
    
gfg = geek.fromfunction(lambda i, j: i == j, (3, 3), dtype = int)
    
print(gfg)


输出 :

代码#2:

Python3

# Python program explaining
# numpy.fromfunction() function
    
# importing numpy as geek
import numpy as geek
    
gfg = geek.fromfunction(lambda i, j: i == j, (3, 3), dtype = int)
    
print(gfg)

输出 :