Random Integer Vector | Linear Algebra using Python

In this tutorial, you will learn about the random integer vector, what is it, and how to implement it using Python?
Submitted by Anuj Singh, on July 05, 2020

Prerequisite:

Random Integer Vector is a type of vector having a random integer value at each entry. Such types of vectors have a huge importance in Simulation and Machine Learning. Random Integer Vector can be defined by its Upper Limit, Lower Limit, and Length of the Vector (i.e. number of entries).

In this article, we are going to create a random integer vector using inbuilt function numpy.random.randint().

Syntax:

numpy.random.randint(low, up, length)

low - lower limit for choosing random integer value
up - upper limit for choosing random integer value
length - Length of the desired vector

Application:

  1. Machine Learning
  2. Probability
  3. Constraint Based Programming
  4. Monte Carlo Simulation

Python program for random integer vector

# Linear Algebra Learning Sequence
# Random Integer Vector

import numpy as np

# Example 1, length 20
t1 = np.random.randint(0,30,20)
print('Example : ', t1)

# Example 2, length 20
t2 = np.random.randint(0,100,20)
print('\n\nExample : ', t2)

# Example 3, length 20
t3 = np.random.randint(0,300,20)
print('\n\nExample : ', t3)

# Example 4, length 30
t4 = np.random.randint(40,45,30)
print('\n\nExample : ', t4)

Output:

Example :  [ 6  2 14 27 23 12 15  7 23 18 17 16 13 12 19  7 27 21 28 23]


Example :  [65 41 80 12 12 91 10 77 31 66 29 98 11 40 41 52  7 18 80 26]


Example :  [126  14 190  21 259 268 168  88 252 270 243 112 237 2  
38 112 229 106 85  48]


Example :  [44 40 42 40 42 42 44 43 43 42 41 42 42 44 42 41 41 40 
40 42 43 40 42 40 44 44 40 43 40 40]


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.