How to Divide each element of a matrix by a numerical value?

How to Divide each element of a matrix by a numerical value?

This recipe helps you Divide each element of a matrix by a numerical value
In [1]:
## How to Divide each electment of a matrix by a numerical value
def Kickstarter_Example_18():
    print()
    print(format('How to divide each element of a matrix by a numerical value',
                 '*^72'))

    # Load library
    import numpy as np

    # Create two vectors
    matrixA = np.array([[2, 3, 23],
                       [5, 6, 25],
                       [8, 9, 28]])

    # Create a function that adds 100 to something
    add_100 = lambda i: i / 9

    # Create a vectorized function
    vectorized_add_100 = np.vectorize(add_100)

    # Apply function to all elements in matrix
    print(); print(vectorized_add_100(matrixA))

Kickstarter_Example_18()
******How to divide each element of a matrix by a numerical value*******

[[0.22222222 0.33333333 2.55555556]
 [0.55555556 0.66666667 2.77777778]
 [0.88888889 1.         3.11111111]]


Stuck at work?
Can't find the recipe you are looking for. Let us know and we will find an expert to create the recipe for you. Click here
Companies using this Recipe
1 developer from Infosys
1 developer from Vodafone
1 developer from Altimetrik
1 developer from KPMG
1 developer from YASH Technologies
1 developer from ANAC
1 developer from LTI
1 developer from HvH
1 developer from MudraCircle