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.

Program to check whether the dimensions of two arrays are the same or not

In this python numpy program, we will check whether the dimensions of two arrays are the same or not.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create two arrays using np.array().
  3. Use an if-else statement with shape to check whether the dimensions of two arrays are the same or not.
  4. Print the output.
				
					import numpy as np
x = np.arange(15).reshape(3,5)
y = np.arange(20).reshape(4,5)

if x.shape == y.shape:
    print("Same dimensions")
else:
    print("Different dimensions")
				
			

Output :

				
					Different dimensions
				
			

Create an array and reshape it.

calculate the sin angle of an array.

Program to create a NumPy array and reshape it

In this python numpy program, we will create a NumPy array and reshape it.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array using np.array().
  3. Reshape the given array to 5 rows and 6 columns using reshape.
  4. Print the output.
				
					import numpy as np
x = np.arange(30)
y = x.reshape(5,6)

print("Array: \n",y)
				
			

Output :

				
					Array: 
 [[ 0  1  2  3  4  5]
 [ 6  7  8  9 10 11]
 [12 13 14 15 16 17]
 [18 19 20 21 22 23]
 [24 25 26 27 28 29]]
				
			

convert an array to a data frame with headers.

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

Convert a NumPy array to a data frame with headers

In this python numpy program, we will convert a NumPy array to a data frame with headers.

Steps to solve the program
  1. Import the numpy library as np.
  2. Import pandas library as pd.
  3. Create an array using np.array().
  4. Convert an array to a data-frame with headers using pd.DataFrame() and set columns=[‘A’,’B’,’C’].
  5. Print the output.
				
					import numpy as np
import pandas as pd
x = np.random.rand(6,3)

df = pd.DataFrame(x,columns=['A','B','C'])
print("\nPandas DataFrame: ")
print(df)
				
			

Output :

				
					Pandas DataFrame: 
          A         B         C
0  0.307619  0.526206  0.982625
1  0.865438  0.248926  0.248677
2  0.080811  0.619051  0.774105
3  0.716698  0.419266  0.181618
4  0.223379  0.055573  0.168672
5  0.106160  0.929609  0.886170
				
			

create an array and reshape it.