Il Thu, 24 Jun 2021 18:07:07 +0200, Julio Di Egidio ha scritto: > On 24/06/2021 16:23, jo wrote: >> Hi, >> >> this code generate 4 values with gaussian distribution (mu=5, sigma=1): >> >> import numpy as np x = np.random.normal(5, 1, 4) >> print(x) >> >> Output: >> [5.87879753 3.29162433 3.83024698 4.92997148] >> >> I would like to round the output like this: >> >> [6, 3, 4, 5] >> >> What should I add to the code? >> >> Thank you > > Have a look at numpy.around: > <https://numpy.org/doc/stable/reference/generated/numpy.around.html> > > HTH, > > Julio
Yes, np.around() works fine. Thank you. This is the new code: import numpy as np x = np.random.normal(5, 1, 4) y=np.around(x) print(x) print(y) output: [4.68551569 3.9610641 6.1119447 4.81012246] [5. 4. 6. 5.] Thank you very much, j. -- https://mail.python.org/mailman/listinfo/python-list