0% found this document useful (0 votes)
98 views2 pages

Module 4 - 1

The document contains 12 code snippets that perform various operations with NumPy arrays: 1. Extract data from a CSV file into NumPy arrays 2. Filter elements greater than 5 from a 2D array 3. Generate a random 10x10 array and find min and max values 4. Calculate mean of random 1D array of size 30 5. Create array from 0 to 10 and negate elements between 3 and 9 6. Sort random 3x3 array by columns 7. Get sum over last two axes of 4D array

Uploaded by

deepakkashya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
98 views2 pages

Module 4 - 1

The document contains 12 code snippets that perform various operations with NumPy arrays: 1. Extract data from a CSV file into NumPy arrays 2. Filter elements greater than 5 from a 2D array 3. Generate a random 10x10 array and find min and max values 4. Calculate mean of random 1D array of size 30 5. Create array from 0 to 10 and negate elements between 3 and 9 6. Sort random 3x3 array by columns 7. Get sum over last two axes of 4D array

Uploaded by

deepakkashya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

1.

Extract data from the given CSV file and store the data from each column in a
separate NumPy array

import pandas
import numpy

N=1
y = pandas.read_csv('F:/Usman/FairDealCustomerDatanew.csv')
z=set(numpy.array(y.name))
m=set(numpy.array(y.Location))
print(z)
print(m)

6. Create a numpy array [[0, 1, 2], [ 3, 4, 5], [ 6, 7, 8],[ 9, 10, 11]]) and
filter the elements greater than 5.

import numpy

t=numpy.array([[0, 1, 2], [ 3, 4, 5], [ 6, 7, 8],[ 9, 10, 11]])

z=t.ravel()
m=[]
for i in range(12):
if i>5:
m.append(i)
print(m)

8. Create a 10x10 array with random values and find the minimum and maximum values.
import pandas
import numpy

t=numpy.random.random((10,10))
m=t.ravel()
f=m.max()
n=m.min()

print(f,n)

9. Create a random vector of size 30 and find the mean value.

import pandas
import numpy

y=numpy.arange(1,31)

x=0
for i in range(30):
x=x+i

10. Create numpy array having elements 0 to 10 And negate all the elements between
3 and 9
import numpy

y=numpy.arange(0,10)

x=[]
for i in range(3,9):
x.append(i*-1)

import numpy

11. Create a random array of 3 rows and 3 columns and sort it according to 1st
column, 2nd column or 3rd column.

rand = numpy.random.RandomState(42)
X = rand.randint(0, 10, (4, 6))

y=numpy.sort(X,axis=0)
y=numpy.sort(X,axis=1)

print(X)

12. Create a four dimensions array get sum over the last two axis at once

import numpy

rand = numpy.random.RandomState(42)
X = rand.randint(0, 10, (4, 6))

y=numpy.sort(X,axis=0)
y=numpy.sort(X,axis=1)
z=numpy.sum(X)

print(z)
print(y)

You might also like