Numpy Arrays (Part-1) - Question and Answers
CBSE Class 11 - Informatics Practices - Python Basics
Q1: The following statement has an error. Write the correct statement.
>>> import numpy as np
>>> a = np.array(1,2,3,4)
Answer: The second statement should be a = np.array([1,2,3,4]) to create an ndarray.
Q2: What is the output of the following program?
import numpy as np
list1 = [1,2,3,4,5]
np1 = np.array(list1)
print(type(np))
print(type(np1))
print(np1[2])
print(np1.shape)
Answer:
<class 'module'>
<class 'numpy.ndarray'>
3
(5,)