-1

Can somebody explain me the following line of C-code and translate it into Python? I have no plan....

x[IX(0 ,i)] = b==1 ? –x[IX(1,i)] : x[IX(1,i)]

The array structure is not important (except that I am interested in a vectorized Numpy form too). I'm interested in understanding the C command. Simplified we can write

D = b==1 ? –A : A

What does this mean? What is the result of D at the end? What's the role of –A : A? How can we write this in Python? How can we write this vectorized in Numpy? Thank you !

pyano
  • 1,885
  • 10
  • 28

2 Answers2

0

Alternative form:

if(b==1)
  D = -A;
else
  D = A;

or

if(b==1)
  x[IX(0 ,i)] = –x[IX(1,i)];
else
   x[IX(0 ,i)] = x[IX(1,i)];

I think in this form it is not difficult to translate to python

0___________
  • 60,014
  • 4
  • 34
  • 74
0

If I understand your question correctly....then this will be the case:

It's a ternary operator method, it's like an alternate for if else. For eg: in this example if the value of b is equal to 1 i.e. condition is true then -A will be stored in D otherwise it will hold A value in D.