How Do I Solve Numpy. Ndarray' Object Has No Attribute 'Histogram' on 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.

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'. Another problem is that this isn't normalized so my results shouldn't be right...

2

1 Answer

I think what you are looking for is to make a histogram plot of a normal distribution. Have you tried using matplotlib library's histogram 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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Chloe Bennett
Author

Chloe Bennett

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.