Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用数组中的每个条目计算数学方程_Python_List_Numpy Ndarray - Fatal编程技术网

Python 使用数组中的每个条目计算数学方程

Python 使用数组中的每个条目计算数学方程,python,list,numpy-ndarray,Python,List,Numpy Ndarray,我有一个数组和一个等式 我想将所有数组值插入到公式中并保存它 到目前为止,我一直在尝试: import math import numpy as np Z_F0=376.73 Epsilon=3.66 wl_range = [np.arange(0.1, 50, 0.1)] wl_array = np.array(wl_range) multiplied_array = 6+(2*math.pi*6)*math.exp(-1*(30.666/wl_array)**0.7528) print(

我有一个数组和一个等式

我想将所有数组值插入到公式中并保存它

到目前为止,我一直在尝试:

import math
import numpy as np

Z_F0=376.73
Epsilon=3.66

wl_range = [np.arange(0.1, 50, 0.1)]
wl_array = np.array(wl_range)
multiplied_array = 6+(2*math.pi*6)*math.exp(-1*(30.666/wl_array)**0.7528)
print(multiplied_array)
或者我尝试了
multipled\u array=np.vectorize(6+(2*math.pi*6)…)

但是我得到了


错误。

您不需要
math
numpy
pi
exp
pi
可以与
math
一起使用,因为它只是一个常量。但是指数的内容是一个向量,因此需要使用
numpy

在某些情况下,
math
更快(当您不进行矢量化时),因为
numpy
对输入维度的检查开销更大

import numpy as np

Z_F0=376.73
Epsilon=3.66

wl_range = [np.arange(0.1, 50, 0.1)]
wl_array = np.array(wl_range)
multiplied_array = 6+(2*np.pi*6)*np.exp(-1*(30.666/wl_array)**0.7528)
print(multiplied_array)
输出:

[ 6.          6.          6.          6.          6.00000001  6.00000015
   6.00000127  6.00000656  6.00002459  6.00007283  6.00018111  6.00039369
   6.0007699   6.00138329  6.00231952  6.00367362  6.00554684  6.00804354
   6.01126831  6.01532348  6.020307    6.02631085  6.03341981  6.04171066
   6.0512517   6.06210249  6.07431393  6.08792837  6.10297998  6.11949516
   6.13749297  6.15698571  6.17797939  6.20047433  6.22446568  6.24994393
   6.27689541  6.30530278  6.33514546  6.36640006  6.39904075  6.43303963
   6.46836702  6.50499181  6.54288169  6.58200341  6.62232297  6.66380586
   6.70641722  6.75012196  6.79488494  6.84067111  6.88744554  6.93517359
   6.98382097  7.03335377  7.08373859  7.13494255  7.18693331  7.23967918
   7.29314908  7.34731259  7.40213999  7.45760222  7.51367097  7.5703186  ...
math.exp()
仅适用于标量参数
x
。如果使用
numpy.exp()

[ 6.          6.          6.          6.          6.00000001  6.00000015
   6.00000127  6.00000656  6.00002459  6.00007283  6.00018111  6.00039369
   6.0007699   6.00138329  6.00231952  6.00367362  6.00554684  6.00804354
   6.01126831  6.01532348  6.020307    6.02631085  6.03341981  6.04171066
   6.0512517   6.06210249  6.07431393  6.08792837  6.10297998  6.11949516
   6.13749297  6.15698571  6.17797939  6.20047433  6.22446568  6.24994393
   6.27689541  6.30530278  6.33514546  6.36640006  6.39904075  6.43303963
   6.46836702  6.50499181  6.54288169  6.58200341  6.62232297  6.66380586
   6.70641722  6.75012196  6.79488494  6.84067111  6.88744554  6.93517359
   6.98382097  7.03335377  7.08373859  7.13494255  7.18693331  7.23967918
   7.29314908  7.34731259  7.40213999  7.45760222  7.51367097  7.5703186  ...