Macm 01
Macm 01
ANAND
HALL NO: 2305A31003
ASSINGMENT : 01
SUBJECT: MACM
Question 1:
[ ]
1 −2 3 4
−5 0 6 −1
Answer the following for the matrix A=
5 2 −3 2
21 20 −29 32
Solution(code):
import numpy as np
A=[[1,-2,3,4],[-5,0,6,-1],[5,2,-3,2],[21,20,-29,32]]
arr=np.array(A)
print(arr)
print(arr[:,0])
print(arr[1,:])
print(max(arr[:,2]))
print(max(abs(arr[:,2])))
print(np.argmax(abs(arr[3,:])))
arr[[0,2],:]=arr[[2,0],:]
print(arr)
print(0.2*arr[1,:])
output:
[ 1 -2 3 4]
[ -5 0 6 -1]
[ 5 2 -3 2]
[ 21 20 -29 32]]
a) [ 1 -5 5 21]
b) [-5 0 6 -1]
c) 6
d) 29
e) 3
f)i) [[ 5 2 -3 2]
[ -5 0 6 -1]
[ 1 -2 3 4]
[ 21 20 -29 32]]
Question 2: [CO 3]
A university is taking inventory of the books they carry at their two biggest bookstores. The
East Campus bookstore carries the following books:
Hardcover: Textbooks-5280; Fiction-1680; NonFiction-2320; Reference-1890
Paperback: Textbooks-1930; Fiction-2705; NonFiction-1560; Reference-2130
The West Campus bookstore carries the following books:
Hardcover: Textbooks-7230; Fiction-2450; NonFiction-3100; Reference-1380
Paperback: Textbooks-1740; Fiction-2420; NonFiction-1750; Reference-1170
In order to work with this information, represent the inventory of each bookstore as using an
organized array of numbers known as a matrix.
a) Find the total inventory between the two bookstores.
b) Find the excess number of books in each category at West Campus inventory than that of East
Campus.
c) Suppose the bookstore manager in East Campus wants to double his inventory. Find the
number of books of each type that he would need.
Solution(code):
import numpy as np
A=[[5280,1680,2320,1890],[1930,2705,1560,2130]]
B= [[7230,2450,3100,1380],[1740,2420,1750,1170]]
a=np.array(A)
b=np.array(B)
c=a+b
d=b-a
e=2*a
print(c)
print(d)
print(e)
output:
a) [[12510 4130 5420 3270]