我试图简单地为下面写的方程式作图:
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()
但是只要我使用此代码,我都会收到消息:
unhashable type: 'numpy.ndarray'
我已经搜索了原因,但是我在Python unhashable type: 'numpy.ndarray'中看到的解决方案似乎与我的解决方案不同。
我该如何纠正并避免发生?
答案 0 :(得分:1)
您在不应该使用括号的地方使用了括号。您需要更换
y= 1/{np.exp(1/x)+1}
以此
y= 1/(np.exp(1/x)+1)