0

I want to define a condition such that whenever an element of sigma1 becomes equal to or less than 0.010545, the element is replaced by 0.010545. The current and desired outputs are attached.

import numpy as np
sigma0=0.02109
a=0.001
b=0.001
t=np.linspace(0,20,10)
sigma1=sigma0-b*t
print("sigma1 =",[sigma1])

The current output is

sigma1 = [array([0.02109   , 0.01886778, 0.01664556, 0.01442333, 0.01220111,
       0.00997889, 0.00775667, 0.00553444, 0.00331222, 0.00109   ])]

The desired output is

sigma1 = [array([0.02109   , 0.01886778, 0.01664556, 0.01442333, 0.01220111,
       0.010545, 0.010545, 0.010545, 0.010545, 0.010545   ])]
0

1 Answer 1

0

You can do that with boolean indexing:

sigma1[sigma1<= 0.010545] = 0.010545

Output:

sigma1 = [array([0.02109   , 0.01886778, 0.01664556, 0.01442333, 0.01220111,
       0.010545  , 0.010545  , 0.010545  , 0.010545  , 0.010545  ])]
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.