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.

Create a vector with values ranging from 1 to 20 using NumPy.

In this python numpy program, we will create a vector with values ranging from 1 to 20 using NumPy.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create a vector with values ranging from 1 to 20 using np.arange().
  3. Print the output.
				
					import numpy as np
x = np.arange(1,21)

print("Array: ",x)
				
			

Output :

				
					Array:  [ 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20]
				
			

generate an array of 5 random numbers from a standard normal distribution.

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

generate an array of 5 random numbers from a standard normal distribution using NumPy.

In this python numpy program, we will generate an array of 5 random numbers from a standard normal distribution using NumPy.

Steps to solve the program
  1. Import the numpy library as np.
  2. Generate an array of 5 random numbers from a standard normal distribution using np.random.normal(size=5).
  3. Print the output.
				
					import numpy as np
x = np.random.normal(size=5)
print(x)
				
			

Output :

				
					[ 0.07450327 -1.26415493  0.61604056  0.61595139 -1.07081685]
				
			

generate random numbers between 1-2.

create a vector with values ranging from 1 to 20.

Python NumPy program to create a 3×3 matrix

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

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

print(x)
				
			

Output :

				
					[[1 2 3]
 [4 5 6]
 [7 8 9]]
				
			

create an array of integers between 1-100 by the difference of 6 between them.

create a 3×3 identify matrix.

Create an array of integers by the difference of 6 between them using NumPy.

In this python numpy program, we will create an array of integers by the difference of 6 between them using NumPy.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array of integers between 1-100 by the difference of 6 between them using np.arange().
  3. Print the output.
				
					import numpy as np
x = np.arange(1,101,6)

print("Array: ",x)
				
			

Output :

				
					Array:  [ 1  7 13 19 25 31 37 43 49 55 61 67 73 79 85 91 97]
				
			

create an array of odd integers between 1-20.

create a 3×3 matrix.