如何将公式应用于 numpy 数组的每个单元格

How to apply a formula to each cell of a numpy array

我正在尝试采用现有的 numpy 数组并将公式应用于数组的每个单元格。我有下面的代码,但它 returns 出现以下错误。 追溯(最近一次通话): 文件 "C:\gTemp\Text-1.py",第 5 行,位于 myarray = 0.1236 * math.tan(myarray / 2842.5 + 1.1863) 类型错误:只有长度为 1 的数组可以转换为 Python 标量

我是 numpy 的新手,正在寻找适合技能水平的建议。这是我现有的代码。

import arcpy
import numpy
import math
myarray =  numpy.load(r"E:\depthtester2.npy")
myarray = 0.1236 * math.tan(myarray / 2842.5 + 1.1863)
myRaster = arcpy.NumPyArrayToRaster(myarray,arcpy.Point(0.0,0.0),1.0, 1.0, -99999.0 )
myRaster.save("E:\deptht")
print "done"

而不是 math.tan(),使用 numpy.tan()。 numpy 函数旨在按元素对 numpy 数组进行处理。