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.

Generate random numbers between 1-2 using NumPy.

In this python numpy program, we will generate random numbers between 1-2 using NumPy.

Steps to solve the program
  1. From the numpy library import random.
  2. Generate random numbers between 1-2 using random.rand().
  3. Use for loop with the range function to generate 5 numbers.
  4. Print the output.
				
					from numpy import random
for i in range(5):
    rand_num = random.rand()
    print(rand_num)
				
			

Output :

				
					0.9108111865486636
0.6770944961821627
0.4528420505050911
0.7668031795361783
0.4633483035604695
				
			

create a 3×3 identify matrix.

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

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.

Create an array of odd integers between 1-20 using NumPy.

In this python numpy program, we will create an array of odd integers between 1-20 using NumPy.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array of odd integers using np.arange().
  3. Print the output.
				
					import numpy as np
x = np.arange(1,21,2)

print("Array of odd numbers: ",x)
				
			

Output :

				
					Array of odd numbers:  [ 1  3  5  7  9 11 13 15 17 19]
				
			

create an array of even integers between 1-20.

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

Create an array of even integers between 1-20 using NumPy.

In this python numpy program, we will create an array of even integers between 1-20 using NumPy.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array of even numbers using np.arange().
  3. Print the output.
				
					import numpy as np
x = np.arange(2,21,2)

print("Array of even numbers: ",x)
				
			

Output :

				
					Array of even numbers:  [ 2  4  6  8 10 12 14 16 18 20]
				
			

create an array of integers between 1-20.

create an array of odd integers between 1-20.

Create an array of integers between 1-20 using NumPy.

In this python numpy program, we will create an array of integers between 1-20 using NumPy.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array of integers 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]
				
			

create an array of 3 ones.

create an array of even integers between 1-20.

Program to create an array of 3 ones using NumPy.

In this python numpy program, we will create an array of 3 ones using NumPy.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array of 3 ones using np.ones() and give datatype as int and number of ones i.e. 3 to the above function.
  3. Print the output.
				
					import numpy as np
x = np.ones(3, dtype = int)

print(x)
				
			

Output :

				
					[1 1 1]
				
			

determine the size of the memory occupied by the above array.

create an array of integers between 1-20.