Exit Chapter 08 · 🧮 Introduction to NumPy — Quiz

Playing as a guest? to earn XP and track your progress.

Question 1 of 56 0 correct so far

🧮 Introduction to NumPy Quiz

Q1.

What is the full form of NumPy?

Explanation

NumPy stands for Numerical Python.

Q2.

NumPy is a:

Explanation

NumPy is a free, open-source library added to Python for fast numerical work.

Q3.

What is the main object (array) of NumPy called?

Explanation

NumPy's array object is called ndarray.

Q4.

ndarray stands for:

Explanation

An ndarray can have one, two or more dimensions.

Q5.

Who created NumPy?

Explanation

Travis Oliphant created NumPy in 2005.

Q6.

In which year was NumPy created?

Explanation

NumPy was created in 2005.

Q7.

Which command installs NumPy?

Explanation

pip is Python's package installer and is typed at the command prompt.

Q8.

Where is the command pip install numpy typed?

Explanation

pip is a command-prompt command, not a Python statement.

Q9.

Which statement imports NumPy with its usual alias?

Explanation

np is the standard alias (nickname) for numpy.

Q10.

In import numpy as np, np is called a(n):

Explanation

An alias is a short name used in place of numpy.

Q11.

What error do you get if you use np.array([1, 2]) without importing NumPy?

Explanation

Python doesn't know what np is, so it gives NameError: name 'np' is not defined.

Q12.

What error appears for import numpy if NumPy is NOT installed?

Explanation

If the package is missing, Python cannot find the module.

Q13.

Which of these is a reason to use NumPy?

Explanation

NumPy arrays are fast, compact and support element-wise operations.

Q14.

Which libraries studied in Class 12 are built on NumPy?

Explanation

Pandas and Matplotlib are built on top of NumPy.

Q15.

An array is a collection of elements that are:

Explanation

All elements share one type and are stored side by side.

Q16.

What does 'contiguous' mean for array elements?

Explanation

Contiguous means side by side, with no gaps.

Q17.

Indexing of a NumPy array starts from:

Explanation

Like lists, array indexes start at 0.

Q18.

A 1-D array is like:

Explanation

A one-dimensional array is a single row.

Q19.

A 2-D array has:

Explanation

A two-dimensional array is like a table.

Q20.

Which is TRUE about a Python list?

Explanation

A list can mix types, e.g. [1, 'a', 2.5].

Q21.

Which is TRUE about a NumPy array?

Explanation

An array holds one data type only.

Q22.

Which uses LESS memory for a large amount of numbers?

Explanation

Arrays store data compactly.

Q23.

How does a NumPy array print?

Explanation

NumPy prints arrays with spaces between elements.

Q24.

What is the output?

import numpy as np
arr = np.array([10, 20, 30, 40])
print(arr)
Explanation

np.array() converts the list into an array, printed without commas.

Q25.

What is the output?

import numpy as np
arr = np.array([1, 2, 3])
print(type(arr))
Explanation

A NumPy array is of type numpy.ndarray.

Q26.

Which function creates a NumPy array from a list?

Explanation

np.array(list) converts a list into an array.

Q27.

What is the output?

import numpy as np
L = [10, 20, 30]
print(L * 2)
Explanation

For a list, * 2 repeats the list.

Q28.

What is the output?

import numpy as np
A = np.array([10, 20, 30])
print(A * 2)
Explanation

For an array, * 2 multiplies every element (element-wise).

Q29.

What is the output?

import numpy as np
A = np.array([10, 20, 30])
print(A + 5)
Explanation

5 is added to every element.

Q30.

What does [10, 20, 30] + 5 give for a Python LIST?

Explanation

A number cannot be added to a list.

Q31.

Doing an operation on every element of an array at once, like A + 5, is called:

Explanation

NumPy applies the operation to each element without a loop.

Q32.

What is the output?

import numpy as np
marks = [45, 78, 92, 60]
print(np.array(marks) + 5)
Explanation

Grace marks: 5 is added to every element.

Q33.

What is the output?

import numpy as np
a = np.array([1, 2.5, 3])
print(a)
Explanation

Because of 2.5, all elements become floats (upcasting).

Q34.

What is the output?

import numpy as np
b = np.array([7, "x", 9])
print(b)
Explanation

One string makes every element a string.

Q35.

What is the output?

import numpy as np
c = np.array([True, 2, 3])
print(c)
Explanation

True becomes 1 when mixed with integers.

Q36.

NumPy automatically converting all elements to a common type is called:

Explanation

Mixed values are converted to the 'strongest' type present.

Q37.

What is the order of 'strength' used in upcasting?

Explanation

If one element is further along this order, all elements become that type.

Q38.

np.array([1, 2, 3.0]) — what will be the type of all its elements?

Explanation

One float makes all elements floats.

Q39.

Which argument of np.array() is used to choose the data type?

Explanation

Example: np.array([1, 2, 3], dtype=float).

Q40.

What is the output?

import numpy as np
a = np.array([1, 2, 3], dtype=float)
print(a)
Explanation

dtype=float stores every element as a float.

Q41.

What is the output?

import numpy as np
b = np.array([1.9, 2.7, -3.5], dtype=int)
print(b)
Explanation

dtype=int cuts off the decimal part; it does not round.

Q42.

Which attribute shows the data type of an existing array arr?

Explanation

arr.dtype shows the type of the elements, e.g. int64 or float64.

Q43.

What is the output?

import numpy as np
print(np.array([1.5, 2.5]).dtype)
Explanation

Decimal numbers are stored as float64.

Q44.

What does np.array(1, 2, 3) give?

Explanation

np.array() expects one list; the values must be inside [ ].

Q45.

A 2-D array is created from:

Explanation

Each inner list becomes one row.

Q46.

What is the output?

import numpy as np
t = np.array([[1, 2], [3, 4]])
print(t[1])
Explanation

t[1] is the second row.

Q47.

How many rows and columns does np.array([[2.4, 3], [4.91, 7], [0, -1]]) have?

Explanation

There are 3 inner lists (rows), each with 2 values (columns).

Q48.

Why does np.array([[1, 2], [3]]) give an error?

Explanation

The first row has 2 elements and the second only 1.

Q49.

What error does np.array([[1, 2], [3]]) give in current NumPy?

Explanation

Rows of different lengths give ValueError: setting an array element with a sequence...

Q50.

What is the output?

import numpy as np
arr = np.array([10, 25, 40], dtype=float)
print(arr * 2)
Explanation

Each float element is doubled.

Q51.

What is the output?

import numpy as np
subjects = np.array(["CS", "IP", "Maths"])
print(subjects)
Explanation

String arrays print with quotes and no commas.

Q52.

What is the output?

import numpy as np
A = np.array([2, 4, 6])
print(A[0] + A[2])
Explanation

A[0] is 2 and A[2] is 6.

Q53.

Which statement correctly creates a NumPy array from list L = [5, 10, 15, 20]?

Explanation

np.array() is a function, so the list goes inside round brackets.

Q54.

What is the output?

import numpy as np
print(np.array([5, 10, 15, 20]))
Explanation

NumPy pads numbers to the same width, so 5 gets a leading space.

Q55.

Which statement is FALSE?

Explanation

Mixed int and str values are all converted to strings in an array.

Q56.

A list is like a school bag and a NumPy array is like an egg tray. What does the egg tray show?

Explanation

Arrays hold one type of element, stored side by side.