Is there a more 'mathematical' way to do the following:
1.2738 * (list_of_items)
So for what I'm doing is:
[1.2738 * item for item in list_of_items]
When performing a multiplication of a matrix by a scalar, the resulting matrix will always have the same dimensions as the original matrix in the multiplication. For example, if we multiply c ⋅X the matrix that results from it has the dimensions of X.
The scalar product is commutative. The two manually perpendicular vectors of a scalar product are zero. The two parallel and vectors of a scalar product are equal to the product of their magnitudes. The square of its magnitude is equal to the Self-product of a vector.
Scalar multiplication is the multiplication of a vector by a scalar (where the product is a vector), and is to be distinguished from inner product of two vectors (where the product is a scalar).
The mathematical equivalent of what you're describing is the operation of multiplication by a scalar for a vector. Thus, my suggestion would be to convert your list of elements into a "vector" and then multiply that by the scalar.
A standard way of doing that would be using numpy
.
Instead of
1.2738 * (list_of_items)
You can use
import numpy
1.2738 * numpy.array(list_of_items)
Sample Output:
In [8]: list_of_items
Out[8]: [1, 2, 4, 5]
In [9]: import numpy
In [10]: 1.2738 * numpy.array(list_of_items)
Out[10]: array([ 1.2738, 2.5476, 5.0952, 6.369 ])
Another approach
map(lambda x:x*1.2738,list_of_items)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With