Amazing technological breakthrough possible @S-Logix pro@slogix.in

Office Address

  • #5, First Floor, 4th Street Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 Landmark : Samiyar Madam
  • pro@slogix.in
  • +91- 81240 01111

Social List

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

   Load the sample data.

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

Screenshots
perform array manipulation using Numpy
import libraries
load the sample data from csv file
arithmetic operations of an array using Numpy
Adding and removing elements
Manipulate the arthmetic operator
Splitting the array