• 2nd Floor, #7a, High School Road, Secretariat Colony Ambattur, Chennai-600053 (Landmark: SRM School) Tamil Nadu, India
• pro@slogix.in
• +91- 81240 01111

How to perform array manipulation using Numpy?

Description

To perform array manipulation using numpy.

Input

Array of data. (Iris data)

Output

Array manipulation results.

Process

Create two array.

Do arithmetic operations of an array using Numpy.

Print the results.

Sample Code

#import libraries
import pandas as pd
import numpy as np

#load the sample data from csv file

#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(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”)