LabAssignment_6_NumPy
LabAssignment_6_NumPy
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.