Scalar Multiplication in Python

In this blog post, we will learn how one can do the Scalar Multiplication in Python Programming Language. As we know there are two types of multiplication in matrices. The first one is vector multiplication and the second one is scalar matrix multiplication. There is a special module in python for the purpose of performing operations on matrix.

 

Introduction to Scalar Multiplication in Python

There is a module named NumPy that basically deals with the arrays and matrix in python. To use this module one should import it first into their system. To import this module into the system one should follow the following code:

import numpy as np

This line will import the numpy module into your system aliasing it with the np name. 

The second function is to create arrays using the array() function in the np module. At last, we are using the multiply() function for the scalar multiplication of the arrays or matrixes. In the code, the n variable shows the number with which we want to do the scalar product. The code for the same is as follows:

 

 

# importing the numpy module
import numpy as np

# creating arrays 
array1 = np.array([1, 2, 3])
array2 = np.array([[1, 2], [3, 4]])
n = 5

# doing scalar multiplication of the arrays 
np.multiply(array1,n)
np.multiply(array2,n)

 

 

Output 

 

These are one of the most common and easy ways to perform the above activity in python. 

 

 

Also Read: AlphaStar: Strategy game StarCraft II expertise

 

Share this post

One thought on “Scalar Multiplication in Python

Leave a Reply

Your email address will not be published. Required fields are marked *