In this python numpy program, we will create a vector with values and change the sign of the numbers
Steps to solve the program
- Import the numpy library as np.
- Create a vector with values from 1-15 using np.arange().
Change the sign of the numbers from 6-10 using logic and indexing.
- Print the output.
import numpy as np
x = np.arange(1,16)
x[(x >= 6) & (x <= 10)] *= -1
print(x)
Output :
[ 1 2 3 4 5 -6 -7 -8 -9 -10 11 12 13 14 15]