Program to create a vector with values and change the sign of the numbers.

In this python numpy program, we will create a vector with values and change the sign of the numbers

Steps to solve the program
  1. Import the numpy library as np.
  2. Create a vector with values from 1-15 using np.arange().
  3. Change the sign of the numbers from 6-10 using logic and indexing.

  4. 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]
				
			

create a 2×2 matrix.

multiply two vectors.

Leave a Comment