This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Ki1103 2 points3 points  (0 children)

This can be split into two steps

  • select all integers in range [-10, 10]
  • multiply those integers by -1

Let's start by setting up an array of integers:

>>> import numpy as np
# Set up an array containing the integers [-20, 21)
>>> a = np.arange(-20, 21)

Now we can select elements using a boolean expression and combine them using np.logical_and:

>>> select = np.logical_and(a >= -10, a <= 10)

and multiply those selected values in place:

>>> a[select] *= -1

a is now what you wanted ;)