简体   繁体   English

为什么我在制作 plot 时在 Python 中得到“不可散列的类型:‘numpy.ndarray’?

[英]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.

相关问题 TypeError: unhashable type: 'numpy.ndarray' 尝试 plot 和 DataFrame - TypeError: unhashable type: 'numpy.ndarray' when trying to plot a DataFrame 在 python TypeError: unhashable type: 'numpy.ndarray' - in python TypeError: unhashable type: 'numpy.ndarray' Python不可用类型:'numpy.ndarray' - Python unhashable type: 'numpy.ndarray' 类型错误:不可散列类型:Python 中的“numpy.ndarray” - TypeError: unhashable type: 'numpy.ndarray' in Python TypeError: unhashable type: 'numpy.ndarray' 尝试使用 numpy 绘图时 - TypeError: unhashable type: 'numpy.ndarray' when attempting to make plot using numpy TypeError: unhashable type: 'numpy.ndarray' plot 图 - TypeError: unhashable type: 'numpy.ndarray' plot graph plt.plot TypeError: unhashable type: 'numpy.ndarray' - plt.plot TypeError: unhashable type: 'numpy.ndarray' 尝试从两个不同的 .nc 文件中绘制向量时出现错误“unhashable type: 'numpy.ndarray'” - Getting error "unhashable type: 'numpy.ndarray' " while trying to plot vectors from two different .nc files 尝试从数据集创建散点图时,TypeError:无法散列的类型:'numpy.ndarray' - TypeError: unhashable type: 'numpy.ndarray' when trying to create scatter plot from dataset TypeError:不可散列的类型:Python 程序中的“numpy.ndarray” - TypeError: unhashable type: 'numpy.ndarray' in Python program
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM