Python for Data Science Week-2 Assignment-2
Section A: Basics of NumPy Section B: Array Creation & Attributes
1. NumPy stands for: 5. What is the output?
A) Numerical Python import numpy as np
B) Number Python arr = [Link]([1,2,3,4,5,6])
C) Numeric Processing print([Link])
D) New Python A) 6
Answer: A B) 2
Explanation: C) 1
Page 1 states NumPy stands for Numerical D) (6,)
Python. Answer: C
Explanation:
2. NumPy arrays store: Page 2 shows 1D array → ndim = 1.
A) Mixed data types
B) Only string values 6. What is the shape of:
C) Same data type values [Link](3,2)
D) Only integers A) (2,3) B) (3,2)
Answer: C C) (6,) D) (1,6)
Explanation: Answer: B
Page 1: Arrays contain values of the same data Explanation:
type. Page 2 shows reshape(3,2) → shape (3,2).
3. The rank of an array refers to: 7. What does reshape(3,-1) mean?
A) Size of array A) Error
B) Number of dimensions B) Automatically infer one dimension
C) Number of elements C) Delete dimension
D) Data type D) Make 3D array
Answer: B Answer: B
Explanation: Explanation:
Page 1: Number of dimensions = rank of array. Page 2: -1 automatically calculates required
dimension.
4. Shape of an array represents:
A) Total elements 8. What is ndim of array reshaped as (3,2)?
B) Data type A) 1 B) 2
C) Size along each dimension C) 3 D) 6
D) Memory size Answer: B
Answer: C Explanation:
Explanation: Page 2 shows ndim = 2.
Page 1: Shape is a tuple giving size along each
dimension. 9. What is output?
a = [Link](24)
print([Link])
A) 24 B) 2
C) 1 D) Error
Answer: C
Explanation:
Page 3: arange(24) creates 1D array.
10. What is shape of: 15. [Link](x,y) is equivalent to:
[Link](6,4,1) A) x - y
A) (6,4) B) (6,4,1) B) x * y
C) (24,) D) (4,6) C) x + y
Answer: B D) [Link](y)
Explanation: Answer: C
Page 4 shows reshape(6,4,1) example.
16. What is x - y?
Section C: NumPy Attributes A) [[-4,-4],[-4,-4]]
B) [[4,4],[4,4]]
11. What does itemsize represent? C) [[1,2],[3,4]]
A) Total array size D) Error
B) Size of one element in bytes Answer: A
C) Shape Explanation:
D) Dimensions Page 5 subtraction example.
Answer: B
Explanation: 17. x * y performs:
Page 4: itemsize returns length of each element in A) Matrix multiplication
bytes. B) Element-wise multiplication
C) Division
12. If dtype is int8, itemsize is: D) Error
A) 4 B) 8 Answer: B
C) 1 D) 2
Answer: C 18. What is x * y?
Explanation: A) [[5,12],[21,32]]
Page 4 shows int8 → 1 byte. B) [[19,22],[43,50]]
C) [[6,8],[10,12]]
13. If dtype is float32, itemsize is: D) Error
A) 4 B) 8 Answer: A
C) 2 D) 1
Answer: A 19. [Link](y) gives:
Explanation: A) Element-wise multiplication
Page 4 shows float32 → 4 bytes. B) Matrix multiplication
C) Subtraction
Section D: Arithmetic Operations D) Division
Answer: B
Given:
x = [Link]([[1,2],[3,4]]) 20. What is [Link](y)?
y = [Link]([[5,6],[7,8]]) A) [[5,12],[21,32]]
B) [[19,22],[43,50]]
14. What is x + y? C) [[6,8],[10,12]]
A) [[6,8],[10,12]] D) Error
B) [[5,6],[7,8]] Answer: B
C) [[1,2],[3,4]] Explanation:
D) Error Page 5 shows dot product result.
Answer: A
Explanation:
Page 5 shows element-wise addition.
21. [Link](x,y) is equivalent to: Section E: Advanced Conceptual
A) x*y B) x+y
C) [Link](y) D) x/y 28. [Link](24) creates:
Answer: C A) List B) Tuple
C) 1D NumPy array D) 2D array
22. x / y performs: Answer: C
A) Integer division
B) Matrix division 29. reshape does NOT change:
C) Element-wise division A) Shape
D) Error B) Data arrangement
Answer: C C) Number of elements
D) Dimensions
23. What is [Link](x)? Answer: C
A) [4,6] B) [3,7]
C) 10 D) 4 30. Which operation performs matrix
Answer: C multiplication?
Explanation: A) *
Page 6: sum of all elements = 10. B) dot()
C) +
24. [Link](x, axis=0) gives: D) /
A) Row sum Answer: B
B) Column sum Section A: Array Structure & Attributes
C) Total sum
D) Error 1. What is the output?
Answer: B import numpy as np
a = [Link]([1,2,3,4,5,6])
25. [Link](x, axis=1) gives: b = [Link](2,3)
A) Column sum print([Link], [Link])
B) Row sum A) (2,3) 1
C) Total sum B) (2,3) 2
D) Error C) (3,2) 2
Answer: B D) (6,) 1
Answer: B
26. Output of: Explanation:
[Link](x, axis=0) Reshaping into 2×3 creates 2D array.
A) [4,6] Shape = (2,3), ndim = 2. (Page 2)
B) [3,7]
C) [10] 2. What is the output?
D) 10 a = [Link](12)
Answer: A b = [Link](3,-1)
print([Link])
27. Output of: A) (3,4) B) (4,3)
[Link](x, axis=1) C) (3,3) D) Error
A) [4,6] Answer: A
B) [3,7] Explanation:
C) [10] 12 elements → reshape(3,-1) → 3 rows, 4
D) Error columns. (Page 2)
Answer: B
3. What is ndim after: Answer: C
a = [Link](24) (Page 4)
b = [Link](6,4,1)
print([Link]) 8. What is memory used by float32 array of
A) 1 shape (2,3)?
B) 2 A) 12 bytes
C) 3 B) 24 bytes
D) 4 C) 6 bytes
Answer: C D) 48 bytes
Explanation: Answer: B
Shape (6,4,1) → 3 dimensions. (Page 4) Explanation:
2×3 = 6 elements
4. What is the total number of elements in 6×4 bytes = 24 bytes
shape (3,4,2)?
A) 9 Section C: Arithmetic Operations
B) 12 Given:
C) 24 x = [Link]([[1,2],[3,4]])
D) 6 y = [Link]([[5,6],[7,8]])
Answer: C
Explanation: 9. What is x + y?
3×4×2 = 24 A) [[6,8],[10,12]]
B) [[5,6],[7,8]]
5. What happens if reshape dimensions C) [[19,22],[43,50]]
mismatch total elements? D) Error
A) Automatically adjusts Answer: A
B) Pads zeros (Page 5)
C) Raises error
D) Deletes elements 10. What is x * y?
Answer: C A) Matrix multiplication
B) Element-wise multiplication
Section B: itemsize & Memory C) Division
D) Error
6. If dtype is int8, what is total memory used by Answer: B
array of size 10?
A) 10 bytes 11. What is [Link](y)?
B) 80 bytes A) [[5,12],[21,32]]
C) 1 byte B) [[19,22],[43,50]]
D) 4 bytes C) [[6,8],[10,12]]
Answer: A D) [[-4,-4],[-4,-4]]
Explanation: Answer: B
int8 → 1 byte per element (Page 4). (Page 5)
10×1 = 10 bytes.
12. What is [Link](x,y)?
7. If dtype is float32, itemsize is: A) [[-4,-4],[-4,-4]]
A) 1 B) [[4,4],[4,4]]
B) 2 C) [[6,8],[10,12]]
C) 4 D) Error
D) 8 Answer: A
13. What is x / y? 19. What is [Link](x)?
A) Element-wise division A) 10
B) Matrix inverse B) [4,6]
C) Floor division C) [3,7]
D) Error D) 4
Answer: A Answer: A
(Page 6)
20. What is [Link](x, axis=0)?
Section D: Dot Product & Matrix Logic A) [4,6]
B) [3,7]
14. For matrices of shape (2,3) and (3,2), result C) 10
shape of dot product is: D) Error
A) (2,3) B) (3,2) Answer: A
C) (2,2) D) (3,3)
Answer: C 21. What is [Link](x, axis=1)?
A) [4,6]
15. Dot product requires: B) [3,7]
A) Same shape C) 10
B) Same rows D) Error
C) Columns of first = rows of second Answer: B
D) Square matrix
Answer: C Section F: Conceptual Depth
16. What is result of: 22. [Link](24).reshape(2,3,4) → ndim?
[Link]([[1,0],[0,1]], [[5,6],[7,8]]) A) 1
A) Identity matrix B) 2
B) [[5,6],[7,8]] C) 3
C) [[1,1],[1,1]] D) 4
D) Error Answer: C
Answer: B
Explanation: 23. Which operation does NOT change number
Multiplying by identity returns same matrix. of elements?
A) reshape
Section E: Axis-Based Operations B) dot
C) addition
17. What does axis=0 represent? D) multiplication
A) Row-wise B) Column-wise Answer: A
C) Diagonal D) Total
Answer: B 24. Which operation is element-wise?
(Page 6) A) dot
B) *
18. What does axis=1 represent? C) reshape
A) Column-wise D) sum
B) Row-wise Answer: B
C) Total
D) Error
Answer: B
25. What is output? 30. What is the output?
a = [Link](6).reshape(2,3) a = [Link](6)
print([Link][1]) b = [Link](3,2)
A) 2 c = [Link](-1)
B) 3 print([Link])
C) 6 A) (6,)
D) Error B) (3,2)
Answer: B C) (2,3)
D) Error
26. What is output? Answer: A
a = [Link](6).reshape(2,3) Explanation:
print(len(a)) Reshaping back to 1D gives shape (6,).
A) 6
B) 3 Hard-Level MCQs – Python for Data Science
C) 2
D) Error Section A — NumPy Array Operations
Answer: C
Explanation: 1. What is the output?
len() returns size of first dimension. import numpy as np
a = [Link]([[1,2],[3,4]])
27. Which function performs matrix b = [Link]([[2,0],[1,2]])
multiplication? print(a + b)
A) multiply() A) [[3 2] [4 6]] B) [[2 2] [3 6]]
B) add() C) [[3 0] [3 8]] D) Error
C) dot() Answer: A
D) sum() Explanation
Answer: C Addition is element-wise.
[1+2 2+0]
28. Which operator performs element-wise [3+1 4+2]
multiplication? Result: [[3 2] [4 6]]
A) @
B) dot() 2. What is the output?
C) * import numpy as np
D) multiply() a = [Link]([[1,2],[3,4]])
Answer: C b = [Link]([[5,6],[7,8]])
print([Link](a,b))
29. If x has shape (3,2) and y has shape (2,3), A) [[5 12] [21 32]] B) [[6 8] [10 12]]
result of [Link](y) is: C) [[19 22] [43 50]] D) Error
A) (3,2) Answer: C
B) (2,3) Explanation: Matrix multiplication:
C) (3,3) [1 2] × [5 6]
D) (2,2) [3 4] [7 8]
Answer: C 1*5+2*7 = 19
1*6+2*8 = 22
3*5+4*7 = 43
3*6+4*8 = 50
Result
[[19 22]
[43 50]]
3. What is the output? 7. What is the output?
import numpy as np s = {1,2,3}
a = [Link](6) print(len(s))
print([Link](2,3).shape) A) 1
A) (6,) B) (2,3) B) 2
C) (3,2) D) Error C) 3
Answer: B D) Error
Explanation Answer: C
reshape(2,3) creates a 2-row, 3-column matrix. Explanation
Set has 3 unique elements.
4. What is the output?
import numpy as np 8. What is the output?
a = [Link](9).reshape(3,3) l = [1,2,3]
print(a[1]) print(l*2)
A) [0 1 2] B) [3 4 5] A) [1,2,3,1,2,3]
C) [6 7 8] D) Error B) [2,4,6]
Answer: B C) Error
Explanation: a[1] accesses the second row. D) [[1,2,3],[1,2,3]]
[[0 1 2] Answer: A
[3 4 5] Explanation
[6 7 8]] List multiplication repeats the list.
5. What is the output? 9. Which Python datatype is immutable?
import numpy as np A) List
a = [Link](5) B) Dictionary
b = a[1:4] C) Tuple
b[0] = 10 D) Set
print(a) Answer: C
A) [0 1 2 3 4] Explanation
B) [0 10 2 3 4] Tuples cannot be modified after creation.
C) [0 1 10 3 4] Python for Data Science A-2 Ans
D) Error
Answer: B 10. What is the output?
Explanation t = (1,2,3)
NumPy slicing returns a view, not a copy. print(t[1])
So modifying b changes the original array. A) 1 B) 2
C) 3 D) Error
Section B — Python Data Structures Answer: B
Explanation: Tuple indexing starts at 0.
6. Which object does NOT support indexing?
A) List Section C — Dictionary Operations
B) Tuple
C) Dictionary 11. What is the output?
D) Set d = {'a':1,'b':2}
Answer: D d['c'] = 3
Explanation print(len(d))
Sets are unordered collections, so indexing is not A) 2
supported. B) 3
C) 1 s = "python"
D) Error print(s[1:4])
Answer: B A) pyt
Explanation B) yth
A new key-value pair is added. C) tho
D) pyth
12. What is the output? Answer: B
d = {1:'a',2:'b'} Explanation
print([Link](3,'missing')) Index slicing:
A) missing python
B) None 012345
C) Error 1:4 → y t h
D) 3
Answer: A 17. What is the output?
Explanation s = "HELLO"
get() returns default value if key does not exist. print([Link]())
A) HELLO B) hello
13. What is the output? C) Hello D) Error
d = {1:'a',2:'b'} Answer: B
print(1 in d)
A) True Section E — Combined Logical Thinking
B) False
C) Error 18. What is the output?
D) None l = [1,2,3]
Answer: A print(l[-1])
Explanation A) 1 B) 2
Membership operator checks keys. C) 3 D) Error
Answer: C
14. Which operation modifies dictionary? Explanation
A) [Link]() Negative index counts from end.
B) [Link]()
C) [Link]() 19. What is the output?
D) [Link]() l = [1,2,3]
Answer: C [Link](4)
print(len(l))
Section D — String & Sequence A) 3 B) 4
C) 5 D) Error
15. What is the output? Answer: B
print("-".join(["data","science"]))
A) data science 20. What is the output?
B) data-science print(bool([]))
C) datascience A) True
D) Error B) False
Answer: B C) Error
Explanation D) None
join() concatenates elements with separator. Answer: B
Python for Data Science A-2 Ans Explanation
Empty containers evaluate to False.
16. What is the output?
Section F — Harder Logical Questions 26. What is the output?
print(len("DataScience"))
21. What is the output? A) 10
print(3 > 2 > 1) B) 11
A) True C) 12
B) False D) 9
C) Error Answer: B
D) None
Answer: A 27. What is the output?
Explanation print(list(range(3)))
Equivalent to: A) [0,1,2]
3>2 and 2>1 B) [1,2,3]
C) [0,1,2,3]
22. What is the output? D) Error
print(5 == 5.0) Answer: A
A) True
B) False 28. What is the output?
C) Error print(sum([1,2,3,4]))
D) None A) 10
Answer: A B) 9
Explanation C) 8
Values are equal even though types differ. D) Error
Answer: A
23. What is the output?
print(type([1,2,3])) 29. What is the output?
A) list a = [1,2,3]
B) tuple b=a
C) dict b[0] = 5
D) set print(a)
Answer: A A) [1,2,3]
B) [5,2,3]
24. What is the output? C) Error
print({1,2,3} | {2,3,4}) D) None
A) {1,2,3,4} Answer: B
B) {2,3} Explanation
C) {1,4} Both variables reference same list object.
D) Error
Answer: A 30. What is the output?
Explanation print(type({}))
| performs set union. A) set
B) dict
25. What is the output? C) list
print({1,2,3} & {2,3,4}) D) tuple
A) {1,4} Answer: B
B) {2,3} Explanation
C) {1,2,3,4} Empty {} creates dictionary, not set.
D) Error
Answer: B
Section A: Array Structure & Attributes Explanation:
3×4×2 = 24
1. What is the output?
import numpy as np 5. What happens if reshape dimensions
a = [Link]([1,2,3,4,5,6]) mismatch total elements?
b = [Link](2,3) A) Automatically adjusts
print([Link], [Link]) B) Pads zeros
A) (2,3) 1 C) Raises error
B) (2,3) 2 D) Deletes elements
C) (3,2) 2 Answer: C
D) (6,) 1
Answer: B Section B: itemsize & Memory
Explanation:
Reshaping into 2×3 creates 2D array. 6. If dtype is int8, what is total memory used by
Shape = (2,3), ndim = 2. (Page 2) array of size 10?
A) 10 bytes
2. What is the output? B) 80 bytes
a = [Link](12) C) 1 byte
b = [Link](3,-1) D) 4 bytes
print([Link]) Answer: A
A) (3,4) Explanation:
B) (4,3) int8 → 1 byte per element (Page 4).
C) (3,3) 10×1 = 10 bytes.
D) Error
Answer: A 7. If dtype is float32, itemsize is:
Explanation: A) 1
12 elements → reshape(3,-1) → 3 rows, 4 B) 2
columns. (Page 2) C) 4
D) 8
3. What is ndim after: Answer: C
a = [Link](24) (Page 4)
b = [Link](6,4,1)
print([Link]) 8. What is memory used by float32 array of
A) 1 shape (2,3)?
B) 2 A) 12 bytes
C) 3 B) 24 bytes
D) 4 C) 6 bytes
Answer: C D) 48 bytes
Explanation: Answer: B
Shape (6,4,1) → 3 dimensions. (Page 4) Explanation:
2×3 = 6 elements
4. What is the total number of elements in 6×4 bytes = 24 bytes
shape (3,4,2)?
A) 9 Section C: Arithmetic Operations
B) 12 Given:
C) 24 x = [Link]([[1,2],[3,4]])
D) 6 y = [Link]([[5,6],[7,8]])
Answer: C
9. What is x + y? 15. Dot product requires:
A) [[6,8],[10,12]] A) Same shape
B) [[5,6],[7,8]] B) Same rows
C) [[19,22],[43,50]] C) Columns of first = rows of second
D) Error D) Square matrix
Answer: A Answer: C
(Page 5)
16. What is result of:
10. What is x * y? [Link]([[1,0],[0,1]], [[5,6],[7,8]])
A) Matrix multiplication A) Identity matrix
B) Element-wise multiplication B) [[5,6],[7,8]]
C) Division C) [[1,1],[1,1]]
D) Error D) Error
Answer: B Answer: B
Explanation:
11. What is [Link](y)? Multiplying by identity returns same matrix.
A) [[5,12],[21,32]]
B) [[19,22],[43,50]] Section E: Axis-Based Operations
C) [[6,8],[10,12]]
D) [[-4,-4],[-4,-4]] 17. What does axis=0 represent?
Answer: B A) Row-wise
(Page 5) B) Column-wise
C) Diagonal
12. What is [Link](x,y)? D) Total
A) [[-4,-4],[-4,-4]] Answer: B
B) [[4,4],[4,4]] (Page 6)
C) [[6,8],[10,12]]
D) Error 18. What does axis=1 represent?
Answer: A A) Column-wise
B) Row-wise
13. What is x / y? C) Total
A) Element-wise division D) Error
B) Matrix inverse Answer: B
C) Floor division
D) Error 19. What is [Link](x)?
Answer: A A) 10
(Page 6) B) [4,6]
C) [3,7]
Section D: Dot Product & Matrix Logic D) 4
Answer: A
14. For matrices of shape (2,3) and (3,2), result
shape of dot product is: 20. What is [Link](x, axis=0)?
A) (2,3) A) [4,6]
B) (3,2) B) [3,7]
C) (2,2) C) 10
D) (3,3) D) Error
Answer: C Answer: A
21. What is [Link](x, axis=1)? 27. Which function performs matrix
A) [4,6] multiplication?
B) [3,7] A) multiply()
C) 10 B) add()
D) Error C) dot()
Answer: B D) sum()
Answer: C
Section F: Conceptual Depth
28. Which operator performs element-wise
22. [Link](24).reshape(2,3,4) → ndim? multiplication?
A) 1 B) 2 A) @
C) 3 D) 4 B) dot()
Answer: C C) *
D) multiply()
23. Which operation does NOT change number Answer: C
of elements?
A) reshape 29. If x has shape (3,2) and y has shape (2,3),
B) dot result of [Link](y) is:
C) addition A) (3,2)
D) multiplication B) (2,3)
Answer: A C) (3,3)
D) (2,2)
24. Which operation is element-wise? Answer: C
A) dot
B) * 30. What is the output?
C) reshape a = [Link](6)
D) sum b = [Link](3,2)
Answer: B c = [Link](-1)
print([Link])
25. What is output? A) (6,)
a = [Link](6).reshape(2,3) B) (3,2)
print([Link][1]) C) (2,3)
A) 2 D) Error
B) 3 Answer: A
C) 6 Explanation:
D) Error Reshaping back to 1D gives shape (6,).
Answer: B
26. What is output?
a = [Link](6).reshape(2,3)
print(len(a))
A) 6
B) 3
C) 2
D) Error
Answer: C
Explanation:
len() returns size of first dimension.