generation of a vector through algebraic operation

0

I have a "tension" vector with about 30 values inside, to generate a new vector "defo_calculada2" I need to add 0.2 in each value of the "tension" vector, I believe you have a correct way to do this sum in vector < p>

defo_calculada2 = tension + 0.2

    
asked by anonymous 27.06.2018 / 06:29

1 answer

3

The simplest way is to use list comprehension to generate the new list:

tensao = [1, 2, 3, 4, 5]
defo_calculada2 = [t + 0.2 for t in tensao]

print(defo_calculada2)  # [1.2, 2.2, 3.2, 4.2, 5.2]

If you use the NumPy library, simply add it to the array :

import numpy as np

tensao = np.array([1, 2, 3, 4, 5])
defo_calculada2 = tensao + 0.2

print(defo_calculada2)  # [1.2 2.2 3.2 4.2 5.2]
    
27.06.2018 / 13:46