0

I am trying to find a way to write mathematical notation for an if statement in LaTeX.

For example I would like to have this python code in mathematical notation:

def my_function(x):
    result = []
    for ele in x:
        if ele > 0:
            result.append(ele * 2)
        else:
            result.append(0)
    return result

I want every element of x to double if the element is above zero, and the the element is not zero, I want it to be set to zero.

x = [1,3,4, -1,2,-3] should become [2, 6, 8, 0, 4, 0].

When Googling around for the answer I came across Iverson Bracket, but this is not quite what I need, though it is close.

My final result should look something like this:

result = {if x > 0 => x * 2
         {else x => 0

With one big {, and prettier looking, but I don't know how to do this in LaTeX.

Werner
  • 603,163
Akavall
  • 799

0 Answers0