To perform array manipulation using numpy.
Array of data. (Iris data)
Array manipulation 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[:,2])
b = np.array(df.iloc[:,3])
print(“First array\n\n”,a,”\n”)
print(“Second array\n\n”,b,”\n”)
#Array manipulation operation
print(“Trainspose array\n”)
c = np.transpose(b)
print(c.T,”\n”)
print(“Changing array shape\n\n”)
print(b.reshape(3,-2),”\n”)
print(“Adding and removing elements\n\n”)
print(np.append(a,b),”\n”)
print(np.insert(a,1,5),”\n”)
print(np.delete(a,[1]),”\n”)
print(“Combining arrays\n\n”)
print(np.concatenate((a,c),axis=0),”\n”)
print(“Splitting the array (Horizontally)\n\n”)
print(np.hsplit(a,3),”\n”)
print(“Splitting the array (Vertical)\n\n”)
print(np.hsplit(a,3),”\n”)