python - 更改两行的顺序时,我得到 TypeError: 'numpy.ndarray' object is not callable
问题描述
这有效:
import numpy as np
import matplotlib.pyplot as plt
def n(vg):
Eta = 1.825e-5
B = 7e-3
Rho= 900
g = 9.81
# r = (9 * Eta * vg/(2* Rho* g))**0.5
V = 30
P = 1
n = (9 * np.pi * 2 **0.5 * Eta**(3/2) /(Rho * g)**(0.5)) *(1 +B/(((9* Eta* vg/(2 * Rho * g))**0.5)*P))**(-3/2) * ((vg**3/2)/V)
return n
def list_of_n(vg_start,vg_end,d_vg):
n_vg=int((vg_end-vg_start)/d_vg)
if n_vg<1:
print("Error: d_vg is in a way that number of data points is less than one! ")
raise SystemExit
vg= np.linspace(vg_start,vg_end,n_vg)
l=list((i,n(i)) for i in vg)
return np.array(l)
print(list_of_n(0.5,2.5,0.1))
vg,n=list_of_n(0.5,2.5,0.1).T
plt.plot(vg,n,'o',c='Blue')
plt.xlabel(r'$n$',fontsize=14)
plt.ylabel(r'${v}_{g}$',fontsize=14)
plt.show()
但是当我将打印行移到末尾时:
#Same as above
vg,n=list_of_n(0.5,2.5,0.1).T
plt.plot(vg,n,'o',c='Blue')
plt.xlabel(r'$n$',fontsize=14)
plt.ylabel(r'${v}_{g}$',fontsize=14)
plt.show()
print(list_of_n(0.5,2.5,0.1))
我收到以下错误:
Traceback (most recent call last):
File "3.py", line 30, in <module>
print(list_of_n(0.5,2.5,0.1))
File "3.py", line 21, in list_of_n
l=np.array(list((i,n(i)) for i in vg))
File "3.py", line 21, in <genexpr>
l=np.array(list((i,n(i)) for i in vg))
TypeError: 'numpy.ndarray' object is not callable
我在“numpy.ndarray”中意识到 object is not callable 错误,为什么 numpy.ndarray is object is not callable in my simple for python loop that this error意味着我试图将numpy数组作为函数调用,但这与我的问题?
解决方案
推荐阅读
- excel - VBA - 复制链接到列中某个关键字的单元格的类型不匹配错误
- c# - 这个索引器访问定义是什么意思?
- python - Django 使用基于函数的视图和多个表单填充表单
- php - 当我使用 php-client-forge autodesk api 时,404 错误连接到 API (https://developer.api.autodesk.com/modelderivative/v2/designdata/job)
- angular - Some material icon doesn't show in production
- python - tensorflow lite 转换更改模型权重
- python - 如何检查列表 B 中的所有列表元素在列表 A 中出现的频率?
- java - 我不能在摩托罗拉 moto e4 上打电话
- javascript - React 原生滚动子栏目
- c - C中的结构指针