[英]Why am I getting 'unhashable type: 'numpy.ndarray' in Python, when making a plot?
I'm trying to simply make a plot for the equation written below:我试图简单地为下面写的方程制作一个 plot:
import matplotlib.pyplot as plt
import numpy as np
# 100 linearly spaced numbers
x = np.linspace(0,100,100)
y= 1/{np.exp(1/x)+1}
#plot the function
plt.plot(x,y, 'r')
#show the plot
plt.show()
But whenever I use this code, I get the message:但是每当我使用此代码时,我都会收到以下消息:
unhashable type: 'numpy.ndarray'
I have searched for the reason for this but the solutions I have seen such as in Python unhashable type: 'numpy.ndarray' , doesn't seem to be the same as mine.我已经搜索了这个原因,但我看到的解决方案,例如Python unhashable type: 'numpy.ndarray' ,似乎与我的不同。
How can I correct this and avoid it happening?我怎样才能纠正这种情况并避免它发生?
You are using brackets where you should not use it.您在不应该使用括号的地方使用括号。 You need to replace你需要更换
y= 1/{np.exp(1/x)+1}
by this这样
y= 1/(np.exp(1/x)+1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.