generation of a vector through algebraic operation

Asked

Viewed 35 times

0

I have a vector "tensao" with about 30 values inside, to generate a new vector "defo_calculada2" need to add 0.2 in each value of the vector "tensao", I believe it has a correct way to flow this sum in the vector

defo_calculated 2=tense+0.2

1 answer

3

The simplest way is using comprehensilist on 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 using the Numpy library, just add to 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]

Browser other questions tagged

You are not signed in. Login or sign up in order to post.