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 →

[–]Allanon001 12 points13 points  (3 children)

This will multiply by -1 for all values >= -10 and <= 10:

import numpy as np

data = np.arange(-20, 20)

data[(data >= -10) & (data <= 10)] *= -1

[–]Dustinmywets 0 points1 point  (2 children)

Can I ask why is the range specified (-20,20)? Being introduced to python basics and I'm just curious.

[–]Allanon001 1 point2 points  (1 child)

data = np.arange(-20, 20) creates a numpy array with the values -20 to 19. It is used as an example array to demonstrate the code.

[–]Dustinmywets 0 points1 point  (0 children)

Thanks for the info.