A Linear Function Vector | Linear Algebra using Python

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

Prerequisite:

A Linear Vector is a type of vector which has elements following a linear function. For example, a vector [2,4,6,8,10,12,14,16] and [5,8,11,14,17,20,23,26]. We can represent them mathematically as,

y = 2x, for the first example
y = 3x + 5, for the second example

In general, 
y = ax  + b

Where, 
a is a linear multiplicative factor, and 
b is an offset value.

We have an inbuilt function within numpy library which lets us create this mathematical linear function and its data points very easily.

Syntax:

numpy.arange(low, up, mul_a)

low - lower limit as value b (offset)
up - upper limit 
mul_a - multiplicative factor i.e. a

Such types of vectors have applications in Plotting (Data Visualization) and Machine Learning.

Application:

  1. Machine Learning
  2. Plotting and Data Visualization
  3. Constraint Based Programming

Python program for linear function vector

# Linear Algebra Learning Sequence
# Linear Function Vector

import numpy as np

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

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

# Example 3, length 20
t3 = np.arange(24,56)
print('\n\nExample : ', t3)

# Example 4, length 30
t4 = np.arange(50)
print('\n\nExample : ', t4)

Output:

Example :  [ 0  2  4  6  8 10 12 14 16 18 20 22 24 26 28]


Example :  [ 0 14 28 42 56 70 84 98]


Example :  [24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55]


Example :  [ 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49]


Comments and Discussions!

Load comments ↻





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