Home > Software design >  How to get this result when multiplying 1d-array by 2d-array?
How to get this result when multiplying 1d-array by 2d-array?

Time:06-08

I am struggling to figure out, how the output is calculated can you please explain?

I have this

w=np.array([[50, 51, 52, 53, 54],
       [55, 56, 57, 58, 59],
       [60, 61, 62, 63, 64],
       [65, 66, 67, 68, 69],
       [70, 71, 72, 73, 74]])

multiplied by this array :

c = np.array([3267. , 3375.9, 3484.8, 3630., 3740.])

the output is:

array([1050885., 1068309., 1085733., 1103157., 1120581.])

CodePudding user response:

Grasping at straws because it feels like there's not enough information to solve this. But, here is one way to get the result:

import numpy as np

w = np.array(
    [
        [50, 51, 52, 53, 54],
        [55, 56, 57, 58, 59],
        [60, 61, 62, 63, 64],
        [65, 66, 67, 68, 69],
        [70, 71, 72, 73, 74],
    ]
)
c = np.array([3267.0, 3375.9, 3484.8, 3630.0, 3740.0])

r = w.T @ c
d = [4977.5   i * 73.7 for i in range(5)]

result = r - d

result:

array([1050885., 1068309., 1085733., 1103157., 1120581.])
  • Related