Home > Backend Development > Python Tutorial > Detailed explanation of the difference between numpy.random.randn() and rand()

Detailed explanation of the difference between numpy.random.randn() and rand()

不言
Release: 2018-04-17 10:54:01
Original
11493 people have browsed it

The following is a detailed explanation of the difference between numpy.random.randn() and rand(). It has a good reference value and I hope it will be helpful to everyone. Let’s take a look together

numpy There are some commonly used functions used to generate random numbers, randn() and rand() belong to them.

numpy.random.randn(d0, d1, …, dn) returns one or more sample values ​​from the standard normal distribution.

numpy.random.rand(d0, d1, …, dn) ’s random sample is located in [0, 1).

import numpy as np 
arr1 = np.random.randn(2,4)
print(arr1)
print('******************************************************************')
arr2 = np.random.rand(2,4)
print(arr2)
Copy after login

Result:

[[-1.03021018 0.5197033 0.52117459 -0.70102661]
 [ 0.98268569 1.21940697 -1.095241 -0.38161758]]
******************************************************************
[[ 0.19947349 0.05282713 0.56704222 0.45479972]
 [ 0.28827103 0.1643551 0.30486786 0.56386943]]
Copy after login


The above is the detailed content of Detailed explanation of the difference between numpy.random.randn() and rand(). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template