Program to create an array using dtype as complex

In this python numpy program, we will create an array using dtype as complex.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array using np.array() and set dtype = complex.
  3. It will create an array of complex numbers.
  4. Print the output.
				
					import numpy as np
a = np.array([5,4], dtype = complex)

print(a)
				
			

Output :

				
					[5.+0.j 4.+0.j]
				
			

convert a tuple into an array.

Program to convert a tuple into a NumPy array

In this python numpy program, we will convert a tuple into a NumPy array.

Steps to solve the program
  1. Import the numpy library as np.
  2. Convert a tuple into an array using np.asarray().
  3. Print the output.
				
					import numpy as np
x = np.asarray((5,7,0))

print(x)
				
			

Output :

				
					[5 7 0]
				
			

round off the elements in an array using ceil function.

create an array using dtype as complex.

Program to round off the elements in an array using ceil function

In this python numpy program, we will round off the elements in an array using ceil function.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array using np.array().
  3. Round off the elements in an array using np.ceil().
  4. It will round up a decimal number to the next value i.e 12.5 will be 13.
  5. Print the output.

				
					import numpy as np
arr = np.array([12.202, 90.23120, 123.88, 23.202])  

print(np.ceil(arr)
				
			

Output :

				
					[ 13.  91. 124.  24.]
				
			

round off the elements in an array using the floor function.

convert a tuple into an array.

Program to round off the elements in an array using the floor function

In this python numpy program, we will round off the elements in an array using the floor function.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array using np.array().
  3. Round off the elements in an array using np.floor().
  4. It will round up a decimal number to its base value i.e 12.5 will be 12.
  5. Print the output.
				
					import numpy as np
arr = np.array([12.202, 90.23120, 123.88, 23.202])

print(np.floor(arr))
				
			

Output :

				
					[ 12.  90. 123.  23.]
				
			

round off the elements in an array up to two digits.

round off the elements in an array using ceil function.

Program to round off the elements in an array up to two digits

In this python numpy program, we will round off the elements in an array up to two digits.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array using np.array().
  3. Round off the elements in an array up to two digits using np.round().
  4. Print the output.
				
					import numpy as np
arr = np.array([12.202, 90.23120, 123.88, 23.202])  

print(np.round(arr,2))
				
			

Output :

				
					[ 12.2   90.23 123.88  23.2 ]
				
			

calculate the tan angle of an array.

round off the elements in an array using the floor function.

Calculate the tan angle of an array using NumPy

In this python numpy program, we will calculate the tan angle of an array using NumPy.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array using np.array().
  3. Calculate the tan angle of the array using np.tan().
  4. Print the output.
				
					import numpy as np
angle = np.array([45,13])

print(f"Tan of {angle}: ",np.tan(angle))
				
			

Output :

				
					Tan of [45 13]:  [1.61977519 0.46302113]
				
			

calculate the cos angle of an array.

round off the elements in an array up to two digits.

Calculate the cos angle of an array using NumPy

In this python numpy program, we will calculate the cos angle of an array using NumPy.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array using np.array().
  3. Calculate the cos angle of the array using np.cos().
  4. Print the output.
				
					import numpy as np
angle = np.array([45,13])

print(f"Cos of {angle}: ",np.cos(angle))
				
			

Output :

				
					Cos of [45 13]:  [0.52532199 0.90744678]
				
			

calculate the variance of an array.

calculate the tan angle of an array.

Calculate the variance of an array using NumPy

In this python numpy program, we will calculate the variance of an array using NumPy.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array using np.array().
  3. Calculate the variance of the array using np.var().
  4. Print the output.
				
					import numpy as np
age = np.array([20,25,21,23,26,27,26,30,24,26]) 

print("Variance: ",np.var(age))
				
			

Output :

				
					Variance:  7.76
				
			

calculate the standard deviation of an array.

calculate the cos angle of an array.

Calculate the standard deviation of an array using NumPy

In this python numpy program, we will calculate the standard deviation of an array using NumPy.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array using np.array().
  3. Calculate the standard deviation of the array using np.std().
  4. Print the output.
				
					import numpy as np
age = np.array([20,25,21,23,26,27,26,30,24,26]) 

print("Standard Deviation: ",np.std(age))
				
			

Output :

				
					Standard Deviation:  2.7856776554368237
				
			

calculate the sin angle of an array.

calculate the variance of an array.

Calculate the sin angle of an array using NumPy

In this python numpy program, we will calculate the sin angle of an array using NumPy.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array using np.array().
  3. Calculate the sin angle of the array using np.sin().
  4. Print the output.
				
					import numpy as np
angle = np.array([45,13])

print(f"Sin of {angle}: ",np.sin(angle))
				
			

Output :

				
					Sin of [45 13]:  [0.85090352 0.42016704]
				
			

check whether the dimensions of two arrays are the same or not.

calculate the standard deviation of an array.