简体   繁体   English

ufunc 的循环不支持浮点类型的参数 0,它没有可调用的 exp 方法

[英]loop of ufunc does not support argument 0 of type float which has no callable exp method

I am having trouble with an optimization that used to work with a previous version of python...我在使用以前版本的 python 的优化时遇到问题...

I have a function fp = lambda c, x: (c[0])+ (c[1]*((1- np.exp(-x/c[4]))/(x/c[4])))+ (c[2]*((((1-np.exp(-x/c[4]))/(x/c[4])))- (np.exp(-x/c[4]))))+ (c[3]*((((1-np.exp(-x/c[5]))/(x/c[5])))- (np.exp(-x/c[5]))))我有一个 function fp = lambda c, x: (c[0])+ (c[1]*((1- np.exp(-x/c[4]))/(x/c[4])))+ (c[2]*((((1-np.exp(-x/c[4]))/(x/c[4])))- (np.exp(-x/c[4]))))+ (c[3]*((((1-np.exp(-x/c[5]))/(x/c[5])))- (np.exp(-x/c[5]))))

and I need to minimize the error e = lambda c, x, y: (((fp(c,x)-y)**2).sum())我需要最小化错误e = lambda c, x, y: (((fp(c,x)-y)**2).sum())

using the initial parameter values p0 = np.array([0.01,0.01,0.01,0.01,0.01,1.00,1.00])使用初始参数值p0 = np.array([0.01,0.01,0.01,0.01,0.01,1.00,1.00])

basically p = optimize.fmin(e, p0, args=(x,y))基本上p = optimize.fmin(e, p0, args=(x,y))

were x and y are np.arrays (14,) each. x 和 y 分别是 np.arrays (14,)。

So, this used to work but now it throws this error TypeError: loop of ufunc does not support argument 0 of type float which has no callable exp method所以,这曾经可以工作,但现在它抛出了这个错误TypeError: loop of ufunc does not support argument 0 of type float which has no callable exp method

I've done some research and it seems that there is a problem related to np.exp() and some versions of Numpy... Actually this problem appeared when I updated Python and Numpy as well to 3.7 and 1.18.1 repectively.我做了一些研究,似乎存在与np.exp()和 Numpy 的某些版本相关的问题......实际上,当我更新 Python 和 Z55F00E1DAA52B7CB5C5C5BC865E79DBC1Z1 时出现了这个问题。1 和 3 代表。

Any thoughts?有什么想法吗?

The issue may be caused by the fact the elements of your numpy array are not of type int.问题可能是由于您的 numpy 数组的元素不是 int 类型。

This can be fixed by turning your float array into an int one, at the small cost of losing a bit of accuracy.这可以通过将浮点数组转换为 int 数组来解决,但代价是损失了一点准确性。 This fixed the issue for me.这为我解决了这个问题。

import numpy as np

y_int = np.array(y_float, dtype=int)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeError:ufunc 的循环不支持浮点类型的参数 0,它没有可调用的 exp 方法 - TypeError: loop of ufunc does not support argument 0 of type float which has no callable exp method python3 np.exp(matrix1 * matrix2)中的错误-“ufunc循环不支持float类型的参数0,它没有可调用的exp方法” - Error in python3 np.exp(matrix1 * matrix2) - “loop of ufunc does not support argument 0 of type float which has no callable exp method” ufunc 的到期循环中的错误不支持 str 类型的参数 0,该参数没有可调用的日志方法 - Error in due loop of ufunc does not support argument 0 of type str which has no callable log method TypeError: ufunc 的循环不支持 Symbol 类型的参数 0,它没有可调用的 sqrt 方法 - TypeError: loop of ufunc does not support argument 0 of type Symbol which has no callable sqrt method TypeError: ufunc 的循环不支持没有可调用日志方法的 ArrayBox 类型的参数 0 - TypeError: loop of ufunc does not support argument 0 of type ArrayBox which has no callable log method 类型错误:ufunc 的循环不支持没有可调用 sin 方法的 Add 类型的参数 0 - TypeError: loop of ufunc does not support argument 0 of type Add which has no callable sin method 为什么我会收到 numpy.exp 的“ufunc 循环不支持 int 类型的参数 0”错误? - Why do I get the 'loop of ufunc does not support argument 0 of type int' error for numpy.exp? “ufunc循环不支持Mul类型的参数0”是什么意思? - What does "loop of ufunc does not support argument 0 of type Mul" mean? 为什么我会收到日志方法的“ufunc 循环不支持 numpy.ndarray 类型的参数 0”错误? - Why do I get the 'loop of ufunc does not support argument 0 of type numpy.ndarray' error for log method? 尝试集成 function 给出“ufunc 循环不支持 Symbol 类型的参数 0” - Trying to integrate function gives “loop of ufunc does not support argument 0 of type Symbol”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM