Reshape the 2×3 matrix into a 2×2 matrix using NumPy.

In this python numpy program, we will reshape the 2×3 matrix into a 2×2 matrix using NumPy.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create a 2×3 matrix using np.array().
  3. Reshape the 2×3 into a 2×2 matrix using reshape.
  4. Print the output.
				
					import numpy as np
x = np.array([[5,6,7],
              [8,9,10]])
y = x.reshape(3,2)
print(y)
				
			

Output :

				
					[[ 5  6]
 [ 7  8]
 [ 9 10]]
				
			

find the shape of the given matrix.

create a 2×2 zero matrix with elements on the main diagonal equal to 7,8.

Program to find the shape of the given matrix using NumPy.

In this python numpy program, we will find the shape of the given matrix using NumPy.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create a matrix using np.array().
  3. Now find the shape of the matrix using shape.
  4. Print the output.
				
					import numpy as np
x = np.array([[5,6,7],
              [8,9,10]])

print("Shape of the matrix: ",x.shape)
				
			

Output :

				
					Shape of the matrix:  (2, 3)
				
			

create a 2×3 matrix filled with values from 5-10.

reshape the 2×3 matrix into a 2×2 matrix.

Create a 2×3 matrix filled with values from 5-10 using NumPy.

In this python numpy program, we will create a 2×3 matrix filled with values from 5-10 using NumPy.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array filled with values from 5-10 using np.arange().
  3. Now convert the array to create a 2×3 matrix using reshape.
  4. Print the output.
				
					import numpy as np
x = np.arange(5,11)

x.reshape(2,3)
				
			

Output :

				
					array([[ 5,  6,  7],
       [ 8,  9, 10]])
				
			

multiply two vectors.

find the shape of the given matrix.

Program to multiply two vectors using NumPy.

In this python numpy program, we will multiply two vectors using NumPy.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create two arrays using np.array().
  3. Multiply two arrays using .
  4. Print the output.
				
					import numpy as np
x = np.array([4,2,8])
y = np.array([7,3,5])

print(x*y)
				
			

Output :

				
					[28  6 40]
				
			

create a vector with values from 1 to 15 and change the sign of the numbers in the range from 6 to 10.

create a 2×3 matrix filled with values from 5-10.

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.

Program to create a 2×2 matrix using NumPy.

In this python numpy program, we will create a 2×2 matrix using NumPy.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array of 4 elements using np.array() because 2×2 matrix will have 4 elements.
  3. Now convert the array to create a 2×2 matrix using reshape.
  4. Print the output.
				
					import numpy as np
x = np.arange(4)

x.reshape(2,2)
				
			

Output :

				
					array([[0, 1],
       [2, 3]])
				
			

create a 2×3 matrix.

create a vector with values from 1 to 15 and change the sign of the numbers in the range from 6 to 10.

Program to create a 2×3 matrix using NumPy.

In this python numpy program, we will create a 2×3 matrix using NumPy.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array of 6 elements using np.array() because 2×3 matrix will have 6 elements.
  3. Now convert the array to create a 2×3 matrix using reshape.
  4. Print the output.
				
					import numpy as np
x = np.arange(6)

x.reshape(2,3)
				
			

Output :

				
					array([[0, 1, 2],
       [3, 4, 5]])
				
			

create a 3×4 matrix.

create a 2×2 matrix

Program to create a 3×4 matrix using NumPy.

In this python numpy program, we will create a 3×4 matrix using NumPy.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array of 12 elements using np.array() because 3×4 matrix will have 12 elements.
  3. Now convert the array to create a 3×4 matrix using reshape.
  4. Print the output.
				
					import numpy as np
x = np.arange(1,13)

x.reshape(3,4)
				
			

Output :

				
					array([[ 1,  2,  3,  4],
       [ 5,  6,  7,  8],
       [ 9, 10, 11, 12]])
				
			

print all the values from the above array except 1.

create a 2×3 matrix.

Python NumPy program to print all the values from the array.

In this python numpy program, we will print all the values from the array except 20 using NumPy.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array of 1-20 numbers using np.range().
  3. Use for loop to iterate over the numbers in the array.
  4. If the number is not equal to 1 then print that number.
				
					import numpy as np
x = np.arange(1,20)

for val in x:
    if val != 1:
        print(val,end=" ")
				
			

Output :

				
					2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 
				
			

print all the values from the array except 20 using NumPy.

create a 3×4 matrix.

Python NumPy program to print all the values from the array.

In this python numpy program, we will print all the values from the array except 20 using NumPy.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array of 1-20 numbers using np.range().
  3. Use for loop to iterate over the numbers in the array.
  4. If the number is not equal to 20 then print that number.
				
					import numpy as np
x = np.arange(1,20)

for val in x:
    if val != 20:
        print(val,end=" ")
				
			

Output :

				
					1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 
				
			

create a vector with values ranging from 1 to 20.

print all the values from the above array except 1 using NumPy.