Question #607

# In Python, how to create an array of n x m random integers?

Merged questions

Answer

The NumPy function `numpy.random.randint(low, high=None, size=None, dtype='l')`

is devoted to return random numbers. By setting the size option, the function can return a `numpy.ndarray`

of random integer :

```
>>> import numpy as np
>>> np.random.randint(low = 0, high = 10, size=(3,2))
array([[8, 7],
[8, 2],
[6, 2]])
```

3 events in history

Question by

**Alphonsio**01/10/2021 at 12:38:25 PMIn Python, how to create an NumPy array of random integers?

Answer by

**Alphonsio**01/10/2021 at 12:38:01 PMThe NumPy function `numpy.random.randint(low, high=None, size=None, dtype='l')`

is devoted to return random numbers. By setting the size option, the function can return a `numpy.ndarray`

of random integer :

```
>>> import numpy as np
>>> np.random.randint(low = 0, high = 10, size=(3,2))
array([[8, 7],
[8, 2],
[6, 2]])
```

Question by

**Alphonsio**01/10/2021 at 12:31:48 PMIn Python, how to create an array of n x m random integers?

# | ID | Query | URL | Count |
---|

Icons proudly provided by Friconix.