python - NumPy:类型错误:reshape() 获得意外的关键字参数 'order'

标签 python numpy fipy

在 reshape numpy ndarray 时出现以下错误

DeprecationWarning: :func:`reshape` is deprecated, use :func:`numerix.reshape()<numpy.reshape>` instead!
return reshape(newshape, order=order)
Traceback (most recent call last):
File "./render2.py", line 374, in <module>
,u=np.reshape(voltage.grad[0], (ny, nx))
File "/home/jana/Builds/lib/python2.6/site-packages/numpy/core/fromnumeric.py", line 172,  in reshape
return reshape(newshape, order=order)
File "/home/jana/Builds/lib/python2.6/site-packages/fipy/tools/decorators.py", line 151, in newfunc
return func(*args, **kwds)
TypeError: reshape() got an unexpected keyword argument 'order'

下面是给出此错误的代码部分。注意:plot.py是用户定义的模块。

plot.streamlinePlot(x = x
                   ,y = y
                   ,u=np.reshape(voltage.grad[0], (ny, nx))
                   ,v=np.reshape(voltage.grad[1], (ny, nx))
                   ,filename='Analysis/electricFieldStreamPlot_%s.png'
                   ,show=False
                   ,clear=True)

输出

print "Voltage shape =", voltage.shape
print "Voltage.grad[0] shape =", voltage.grad[0].shape
print "ny times nx =", ny*nx 

Voltage shape = (269700,)
Voltage.grad[0] shape = (269700,)
ny times nx = 269700

我正在运行 FiPy 3.0 和 NumPy 1.7.2。 有什么线索吗?谢谢!

最佳答案

您应该通过调用获得所需的结果

from fipy import numerix as nx
nx.reshape(voltage.grad[0], (ny, nx))

FiPy 重写了许多 NumPy 例程,以便以自洽的方式处理其自己的数据结构。使用 FiPy 对象时,您应该始终使用 fipy.numerix 而不是 numpy。

如果您不知道,FiPY 现在包含 MatplotlibStreamViewer这可能会满足您的需求,或者至少会向您展示您需要为自己的显示执行的数据操作。

numpy.reshape()、fipy.numerix.reshape() 和 fipy.CellVariable.reshape() 之间的交互肯定有问题。我已提交a ticket调查此事。感谢您提出问题。

关于python - NumPy:类型错误:reshape() 获得意外的关键字参数 'order',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20927397/

相关文章:

python - 如何在 VB.Net 和 Python 之间创建应用程序编程接口(interface) (API)?

python - 将 SQLAlchemy ORM 查询结果转换为 JSON,而不是创建 ORM 对象

python - 通过 lmfit 模型在 python 中最小化拟合两个洛伦兹

python - 检查数组是否是更大数组的一部分

python-3.x - 如何在 Python 3.3 上安装 Fipy

python - 如何将平流扩散 react 偏微分方程与 FiPy 耦合

python - 寻找 i18ndude 的替代品,或者改进版

python - 使用 matplotlib 绘制 sklearn LinearRegression 输出

python - 值错误 : negative dimensions are not allowed