Professional Documents
Culture Documents
Problem 1
Matrix Manipulations
Lets first create a matrix and perform some manipulations of it.
Using numpy's matrix data structure, define the following matricies:
[ )
3 5 9
A= 3 3 4
5 9 17
[)
2
B= 1
4
[[ 1.]
[-2.]
[ 1.]]
Problem 2
Create a result array by adding the following two NumPy arrays. Next, modify the result
array by calculating the square of each element Input:
a r r a y On e= [ 215 6 9
18 27 )
[4
a r r a y T w o= 15 33
7 1)
24
Problem 3
Print max from axis 0 and min from axis 1 from the following 2-D array.
[ )
34 43 73
s a m p l e A r r a y= 82 22 12
53 94 66
Problem 4
Get the positions where elements of a and b match Input: a = np.array([1,2,3,2,3,4,3,4,5,6])
b = np.array([7,2,10,2,7,4,9,4,9,8]) Desired Output: array([1, 3, 5, 7])
a = np.array([1,2,3,2,3,4,3,4,5,6])
b = np.array([7,2,10,2,7,4,9,4,9,8])
matching_positions = np.where(a == b)
print("Matching Positions: ", matching_positions[0])
Matching Positions: [1 3 5 7]
Problem 5
Given
a= [13 24)
b=
[57 68)
Obtain c and d
[ )
1 2
c= 3 4
5 6
7 8
d= [ 13 2 5 6
4 7 8 )
a = np.array([[1,2], [3,4]])
b = np.array([[5,6], [7,8]])
c = np.vstack((a, b))
print("c: \n", c)
d = np.hstack((a, b))
print("d: \n", d)
c:
[[1 2]
[3 4]
[5 6]
[7 8]]
d:
[[1 2 5 6]
[3 4 7 8]]