简体   繁体   English

如何解决 numpy.ndarray' object 在 python 上没有属性“直方图”

[英]How do I solve numpy.ndarray' object has no attribute 'histogram' on python

I want to randomly select numbers with the probability acording to the sum of 2 normal/gaussian distributions and make a histogram.我想随机 select 数字与概率根据 2 个正态/高斯分布的总和并制作直方图。

basicaly基本上

import numpy as np    
u, vth = 0,1 # mean and standard deviation
    v= np.random.normal(u, vth, 1000)+np.random.normal(-u, vth, 1000)
    v.histogram()

However I get the error numpy.ndarray' object has no attribute 'histogram'.但是我收到错误 numpy.ndarray' object has no attribute 'histogram'。 Another problem is that this isn't normalized so my results shouldn't be right...另一个问题是这没有标准化,所以我的结果不应该是正确的......

I think what you are looking for is to make a histogram plot of a normal distribution.我认为您正在寻找的是制作正态分布的直方图 plot。 Have you tried using matplotlib library's histogram function?您是否尝试过使用 matplotlib 库的直方图 function? It can be done easily like so:它可以像这样轻松完成:

import numpy as np    
u, vth = 0,1 # mean and standard deviation
v= np.random.normal(u, vth, 1000)+np.random.normal(-u, vth, 1000)

import matplotlib.pyplot as plt
plt.hist(v)

直方图

暂无
暂无

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

相关问题 为什么我得到 AttributeError: 'numpy.ndarray' object has no attribute 'replace' in python? - Why do I get AttributeError: 'numpy.ndarray' object has no attribute 'replace' in python? 计算热指数时如何解决 Metpy ('numpy.ndarray' object has no attribute 'to') 错误? - How to solve Metpy ('numpy.ndarray' object has no attribute 'to') error when calculating heat index? 如何解决这个错误:AttributeError: 'numpy.ndarray' object has no attribute 'crop' - How to solve this error: AttributeError: 'numpy.ndarray' object has no attribute 'crop' 子图时如何解决'numpy.ndarray'object has no attribute 'get_figure'错误? - How to solve 'numpy.ndarray' object has no attribute 'get_figure' error when subplotting? Python Pandas:“ numpy.ndarray”对象没有属性“ apply” - Python Pandas: 'numpy.ndarray' object has no attribute 'apply' AttributeError:“numpy.ndarray”对象在 Python 中没有属性“index” - AttributeError: 'numpy.ndarray' object has no attribute 'index' in Python Python - AttributeError:'numpy.ndarray'对象没有属性'append' - Python - AttributeError: 'numpy.ndarray' object has no attribute 'append' Python Opencv'numpy.ndarray'对象没有属性'iteritems' - Python Opencv 'numpy.ndarray' object has no attribute 'iteritems' Python:'numpy.ndarray' 对象没有属性 'violinplot' - Python: 'numpy.ndarray' object has no attribute 'violinplot' Python - AttributeError:'numpy.ndarray'对象没有属性'to' - Python - AttributeError: 'numpy.ndarray' object has no attribute 'to'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM