0% found this document useful (0 votes)
1 views4 pages

Macm 01

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

Macm 01

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

NAME: P.

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

a) Print the 1st column from the matrix


b) Print the 2nd row from the matrix
c) Print the maximum element from the 3rd column
d) Print the absolute maximum element from the 3rd column
e) Print the index of the absolute maximum element from the 4th row
f) Print the matrix A by i) swapping the 1st row with 3rd row and ii) multiply the 2nd row by a scalar
0.5

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]]

ii) [-1. 0. 1.2 -0.2]

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]

[ 3670 5125 3310 3300]]

b) [[1950 770 780 -510]

[-190 -285 190 -960]]

c) [[10560 3360 4640 3780]

[ 3860 5410 3120 4260]]

You might also like