How to multiply individual elements of a list with a number?

bharath picture bharath · Nov 19, 2011 · Viewed 131.6k times · Source
S = [22, 33, 45.6, 21.6, 51.8]
P = 2.45

Here S is an array

How will I multiply this and get the value?

SP = [53.9, 80.85, 111.72, 52.92, 126.91]

Answer

JoshAdel picture JoshAdel · Nov 19, 2011

In NumPy it is quite simple

import numpy as np
P=2.45
S=[22, 33, 45.6, 21.6, 51.8]
SP = P*np.array(S)

I recommend taking a look at the NumPy tutorial for an explanation of the full capabilities of NumPy's arrays:

https://scipy.github.io/old-wiki/pages/Tentative_NumPy_Tutorial