0% found this document useful (0 votes)
2 views

LabAssignment_6_NumPy

This document outlines a lab exercise focused on array processing using NumPy. It includes tasks for practicing basic NumPy operations, matrix manipulations, and generating random arrays. The exercise aims to enhance understanding of NumPy's capabilities compared to traditional lists.

Uploaded by

Ishu Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

LabAssignment_6_NumPy

This document outlines a lab exercise focused on array processing using NumPy. It includes tasks for practicing basic NumPy operations, matrix manipulations, and generating random arrays. The exercise aims to enhance understanding of NumPy's capabilities compared to traditional lists.

Uploaded by

Ishu Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

LAB EXERCISE: 6

Array Processing Using NumPy

Work From Home:


Q.1 Practice the following codes to understand Numpy basics:

Why Numpy when Lists are already exist?:

Imagine_Cases1 = Total_Cases + Death_Cases


Imagine+Cases2 = 3*Total_Cases

NumPy Introduction:
Print(b.shape); print(p.size)
Numpy Operations and Methods:

Print(a*b)
print( xsort[ : :-1] )
Work During the Lab:

Q.1 Declare following two matrices A and B as NumPy arrays. Achieve the following
operations:
1 2 3 2 2 2
𝐴 = #4 5 7 -, 𝐵 = #3 3 3-
8 9 10 4 4 4

a. A+B
b. A–B
c. A*B (Matrix Multiplication)
d. A.*B (Elementwise multiplication)

Q.2
a. Declare a NumPy array A containing 12 even numbers between 0 to 23, as
shown below.
b. Create an another array B of dimensions (4 x 3) of all values as 1.
c. Get the matrix multiplication of B. Get the dimensions, shape and size of the
resultant matrix.
d. Replace the diagonal of B by replacing 1 by 4.
e. Print the second row of matrix A.
f. Extract the third column of matrix A, add 1 to each element and print it.

0 2 4 6 1 1 1
𝐴 = # 8 10 12 14- , 𝐵 = 11 1 12
1 1 1
16 18 20 22 1 1 1

Q.3
a. Generate a NumPy array containing 10 elements randomly generated with
values between 0 and 1.
b. Write a code to calculate number of elements greater than or equal to 0.5
and those less than 0.5 .
c. Write a code to sum all the random values in the array.
d. Write a code to sort the elements.

You might also like