To write a piece of python code to perform arithmetic operations of Numpy array.
Array of data. (Iris data)
Arithmetic operations results.
Load the sample data.
Create two array.
Do arithmetic operations of an array using Numpy.
Print the results.
#import libraries
import pandas as pd
import numpy as np
#load the sample data from csv file
data = pd.read_csv(‘/home/soft50/soft50/Sathish/practice/iris.csv’)
#convert as a data frame
df = pd.DataFrame(data)
a = np.array(df.iloc[:,0])
b = np.array(df.iloc[:,1])
print(“First array\n\n”,a,”\n”)
print(“Second array\n\n”,b,”\n”)
#arithmetic operations
print(“Aritmetic operations results (addition)\n\n”)
print(np.add(a,b))
print(“\n”)
print(“Aritmetic operations results (subtraction)\n\n”)
print(np.subtract(a,b))
print(“\n”)
print(“Aritmetic operations results (Division)\n\n”)
print(np.divide(a,b))
print(“\n”)
#Comparison operations
print(“logical operations (comparison)\n\n”)
print(a != b)
print(“\n”)
print(a>=6,”\n”)
#aggregate functions
print(“Aggregete functions (sum)”)
print(np.sum(a),”\n”)
print(“Aggregete functions (minimum)”)
print(np.min(a),”\n”)
print(“Aggregete functions (mean)”)
print(np.mean(a),”\n”)
#Copying and sorting arrays
print(“Copying and sorting array (Copy)\n\n”)
print(np.copy(a),”\n”)
print(“Copying and sorting array (Sorting)\n\n”)
print(np.sort(a),”\n”)