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) 

histogram

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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.

You Might Also Like