# Difference between randn() and normal() functions

Learn about the Difference between randn() and normal() functions in Python NumPy.
Submitted by Pranit Sharma, on February 28, 2023

NumPy is an abbreviated form of Numerical Python. It is used for different types of scientific operations in python. Numpy is a vast library in python which is used for almost every kind of scientific or mathematical operation. It is itself an array which is a collection of various methods and functions for processing the arrays.

## numpy.random.randn() Vs numpy.random.normal() functions

To understand both methods, we need to understand the concept of normal distribution. A normal distribution is a distribution where the values are more likely to occur near the mean value. There are a bunch of cases of this in nature. E.g., the average high temperature in Dallas in June is, let us say, 95 F. It might reach 100, or even 105 average in one year, but it more typically will be near 95 or 97. Similarly, it might reach as low as 80, but 85 or 90 is more likely.

The numpy.random.normal() draw random samples from a normal (Gaussian) distribution. It takes some parameters like loc, scale, and size. Loc is the center of the distribution. Scale is the standard deviation of the distribution and size is the output shape. Hence, if we need to generate a generic normal distribution, we use normal().

The numpy.random.randn() returns a sample (or samples) from the 'standard normal' distribution. It takes a parameter like (d0, d1, d2, ……dn), these are the dimensions of the returned array, and should be all positive. Hence, if we need to generate a specific normal distribution, we use randn().

Let us understand with the help of an example,

## Python code to demonstrate the difference between randn() and normal() functions

```import numpy as np

# Using random.normal
res = np.random.normal(0,0.1, 10)

# Display result
print("Result:\n",res)
```

Output:

```import numpy as np

# Using random.randn
res = np.random.randn(2, 4)

# Display result
print("Result:\n",res)
```

Output:

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates