Unlike many other programming languages, Python does not have a built-in static array data structure in its core syntax, instead relying heavily on flexible lists and the array module for homogeneous data types. For advanced numerical computations and multi-dimensional matrices, developers utilize the powerful NumPy library. Understanding how Python handles sequential memory allocation, list operations, and vectorization is crucial for optimizing code efficiency. These practice MCQs are designed to test your knowledge of Python’s sequential containers and core array operations.
Python Arrays MCQs
1 min read
Correct Answer: b) np.zeros()
Explanation:
The np.zeros() function returns a new array of given shape and type, filled with zeros.
Correct Answer: b) 3
Explanation:
The len() function on a NumPy array returns the size of the first dimension (the number of rows), which is 3.
Correct Answer: c) np.logspace()
Explanation:
np.logspace() returns numbers spaced evenly on a log scale, whereas np.linspace() uses a linear scale.
Correct Answer: b) The number of dimensions (axes) of the array
Explanation:
The ndim attribute returns an integer representing the number of dimensions or axes of the NumPy array.
Correct Answer: b) h
Explanation:
In Python's built-in array module, 'h' represents a signed short integer (typically 2 bytes), while 'i' represents a signed integer.
Correct Answer: b) arr.reshape(3, 4)
Explanation:
The reshape() method gives a new shape to an array without changing its data, provided the total number of elements matches.
Correct Answer: b) 8
Explanation:
The itemsize attribute returns the length of each element in bytes. A float64 takes 8 bytes of memory.
Correct Answer: c) Both arr.ravel() and arr.flatten()
Explanation:
Both methods return a contiguous flattened 1D array, though ravel() typically returns a view when possible while flatten() allocates a copy.
Correct Answer: b) The smaller array is broadcast across the larger array
Explanation:
NumPy broadcasting rules allow arrays of different shapes to be combined mathematically by stretching the smaller array.
Correct Answer: a) tofile()
Explanation:
The tofile() method writes all items to a file object as machine values.
Correct Answer: b) [2, 0, 2]
Explanation:
In NumPy, boolean arrays can be treated as integers (True is 1, False is 0) during numeric operations.
Correct Answer: a) np.concatenate()
Explanation:
np.concatenate() joins a sequence of arrays along an existing axis.
Correct Answer: b) A 3x3 identity matrix with ones on the main diagonal
Explanation:
np.eye() creates a 2D array with ones on the diagonal and zeros elsewhere.
Correct Answer: c) size
Explanation:
The size attribute returns the total number of elements in the NumPy array.
Correct Answer: a) linspace specifies the number of samples, while arange specifies the step size
Explanation:
np.linspace takes a count parameter for evenly spaced values, whereas np.arange takes a step size.
Correct Answer: b) np.argmax()
Explanation:
np.argmax() returns the indices of the maximum values along a specified axis.
Correct Answer: b) Casts the array to a specified data type
Explanation:
astype() is a copy function that casts the array to the specified dtype.
Correct Answer: b) np.vstack()
Explanation:
np.vstack() stacks arrays in sequence vertically (row wise).
Correct Answer: a) [5, 7, 9]
Explanation:
Arithmetic operations on NumPy arrays are element-wise by default.
Correct Answer: b) remove()
Explanation:
The remove() method searches for the given value and removes the first matching element from the array.
Correct Answer: c) An uninitialized array with arbitrary garbage values in memory
Explanation:
np.empty() allocates memory without initializing its values, making it faster than np.zeros().
Correct Answer: a) fromfile()
Explanation:
The fromfile() function reads items from a file object and appends them to the array.
Correct Answer: b) A 1D array containing only the elements greater than 5
Explanation:
Boolean indexing filters the array, returning a new 1D array with elements that satisfy the condition.
Correct Answer: c) np.median()
Explanation:
np.median() computes the median along the specified axis.
Correct Answer: b) Swaps the rows and columns
Explanation:
The .T attribute is a shorthand for reversing or permuting the axes of an array, effectively transposing a 2D matrix.
Correct Answer: a) np.dot()
Explanation:
np.dot() computes the matrix dot product for 2D arrays (or inner product for 1D arrays).
Correct Answer: b) O(1) amortized
Explanation:
Due to over-allocation strategies, appending to a Python list takes amortized constant time O(1).
Correct Answer: b) np.random.random()
Explanation:
np.random.random() returns random floats in the interval [0.0, 1.0).
Correct Answer: b) The sorted, unique elements of an array
Explanation:
np.unique() finds the unique elements of an array and returns them in sorted order.
Correct Answer: b) pop()
Explanation:
The pop() method removes the item at the given index (defaulting to the end of the array) and returns it.
Correct Answer: b) False
Explanation:
np.all() tests whether all array elements evaluate to True. Since one element is False, it returns False.
Correct Answer: a) np.split()
Explanation:
np.split() splits an array into multiple sub-arrays as specified.
Correct Answer: b) The total bytes consumed by the elements of the array
Explanation:
nbytes gives the total number of bytes consumed by the array data (itemsize * size).
Correct Answer: b) np.std()
Explanation:
np.std() computes the standard deviation along the specified axis.
Correct Answer: b) A view of elements from index 1 up to 5 with a step of 2
Explanation:
NumPy array slices create views (not copies) of the original array data.
Correct Answer: b) np.arange()
Explanation:
np.arange() returns evenly spaced values within a given interval.
Correct Answer: a) True
Explanation:
np.any() tests whether any array element along a given axis evaluates to True.
Correct Answer: a) tolist()
Explanation:
The tolist() method converts the array items into a standard Python list.
Correct Answer: a) Returns elements chosen from x or y depending on condition
Explanation:
np.where() yields elements from x where the condition is True, and from y elsewhere.
Correct Answer: a) arr.flags
Explanation:
The flags attribute returns information about the memory layout of the array (e.g., C_CONTIGUOUS).
Correct Answer: b> Creates an array of the given shape filled with fill_value
Explanation:
np.full() returns a new array of given shape and type, filled with fill_value.
Correct Answer: b) np.cumsum()
Explanation:
np.cumsum() returns the cumulative sum of the elements along a given axis.
Correct Answer: a) [1, 4, 9]
Explanation:
Exponentiation in NumPy is also performed element-wise.
Correct Answer: b) insert()
Explanation:
The insert() method inserts a new item before the specified index in the array.
Correct Answer: b) The indices that would sort an array
Explanation:
np.argsort() returns the indices that would sort an array along a given axis.
Correct Answer: b) np.hstack()
Explanation:
np.hstack() stacks arrays in sequence horizontally (column wise).
Correct Answer: b) int64
Explanation:
On 64-bit platforms, the default integer data type for NumPy arrays is int64.
Correct Answer: a) np.linalg.det()
Explanation:
np.linalg.det() computes the determinant of an array matrix.
Correct Answer: a) Extracts the diagonal elements
Explanation:
When given a 2D array, np.diag() extracts and returns its diagonal elements as a 1D array.
Correct Answer: a) array
Explanation:
The built-in 'array' module provides compact array objects for uniform primitive types.
Correct Answer: a) [1.0, 2.0, 4.0]
Explanation:
np.round() rounds elements to the nearest integer (using round-to-even for .5 values, so 2.5 rounds to 2.0 or bankersen's rounding depending on configuration; wait, numpy uses round-to-even: 2.5 rounds to 2.0, 3.8 rounds to 4.0, let's verify standard numpy round behavior: np.round(2.5) is 2.0).
Correct Answer: a) np.exp()
Explanation:
np.exp() calculates the exponential element-wise for all elements in the array.
Correct Answer: b) A memory buffer containing the actual elements of the array
Explanation:
The data attribute is the memory buffer pointing to the start of the array's data.
Correct Answer: a) np.linspace()
Explanation:
np.linspace creates specified number of samples evenly spaced over a specified interval.
Correct Answer: b) O(n)
Explanation:
Linear search through an unsorted collection takes O(n) time complexity.
Correct Answer: a) np.nonzero()
Explanation:
np.nonzero() returns the indices of the elements that are non-zero.
Correct Answer: b) Limits the values in an array so that they fall between a_min and a_max
Explanation:
np.clip() clips (limits) the values in an array, setting anything below a_min to a_min and above a_max to a_max.
Correct Answer: a) np.linalg.inv()
Explanation:
np.linalg.inv() computes the multiplicative inverse of a matrix.
Correct Answer: a) [6, 7]
Explanation:
NumPy supports scalar broadcasting, adding the scalar 5 to each element of the array.
Correct Answer: a) np.save()
Explanation:
np.save() saves an array to a binary file in NumPy .npy format.
Correct Answer: a) Loads a saved NumPy array from a .npy or .npz file
Explanation:
np.load() is used to read arrays saved with np.save() or np.savez().
Correct Answer: b) np.cross()
Explanation:
np.cross() returns the cross product of two vectors.
Correct Answer: a) Specifies C-style row-major memory layout
Explanation:
order='C' means the array is stored in row-major order (C-style).
Correct Answer: b) np.var()
Explanation:
np.var() computes the variance along the specified axis.
Correct Answer: a) Removes single-dimensional entries from the shape of an array
Explanation:
np.squeeze() removes axes of length 1 from the array shape.
Correct Answer: a) itemsize
Explanation:
itemsize returns the length of one array element in bytes.
Correct Answer: b) [2.0, 3.0, 4.0]
Explanation:
np.ceil() returns the ceiling of the input, element-wise (smallest integer greater than or equal to each element).
Correct Answer: a) np.eye()
Explanation:
np.eye() allows specifying an index offset (k parameter) for the diagonal.
Correct Answer: a) [1.0, 2.0, 3.0]
Explanation:
np.floor() returns the floor of the input, element-wise (largest integer less than or equal to each element).
Correct Answer: a) buffer_info()
Explanation:
buffer_info() returns a tuple (address, length) giving the current memory address and element count.
Correct Answer: a) True
Explanation:
np.isnan() tests element-wise for NaN (Not a Number) and returns True for np.nan.
Correct Answer: a) np.outer()
Explanation:
np.outer() computes the outer product of two vectors.
Correct Answer: a) Whether an element is a scalar value
Explanation:
np.isscalar() tests whether the type of a given object is a scalar type.
Correct Answer: a) np.sort()
Explanation:
np.sort() returns a sorted copy of an array, whereas arr.sort() sorts the array in-place.
Correct Answer: a) Sorts the array in-place
Explanation:
arr.sort() sorts the NumPy array in-place, modifying the original array.
Correct Answer: a) np.linalg.eig()
Explanation:
np.linalg.eig() computes eigenvalues and eigenvectors of a square matrix.
Correct Answer: a) Expands the shape of an array by adding a new axis of size 1
Explanation:
np.expand_dims() introduces a new axis at the specified position, increasing the dimensions by one.
Correct Answer: a) np.argmin()
Explanation:
np.argmin() returns the indices of the minimum values along a given axis.
Correct Answer: a) Positive infinity
Explanation:
np.inf is a floating-point representation of positive infinity.
Correct Answer: a) np.log()
Explanation:
np.log() calculates the natural logarithm (base e) element-wise.
Correct Answer: a) A deep copy of the array and its data in memory
Explanation:
np.copy() creates an explicit copy of the array data, ensuring modifications do not affect the original.
Correct Answer: a) np.sum()
Explanation:
np.sum() returns the sum of array elements over a given axis.
Correct Answer: a) True
Explanation:
np.isinf() tests element-wise for positive or negative infinity, returning True for np.inf.
Correct Answer: a) np.inner()
Explanation:
np.inner() computes the inner product of two vectors.
Correct Answer: a) The single character type code used to create the array
Explanation:
The typecode attribute returns the character type code (e.g., 'i', 'f', 'd') used when initializing the array.
Correct Answer: c) Both np.abs() and np.absolute()
Explanation:
Both np.abs() and np.absolute() calculate the absolute value element-wise.
Correct Answer: a) Generates num evenly spaced samples over the specified interval [start, stop]
Explanation:
np.linspace returns num evenly spaced samples, calculated over the interval [start, stop].
Correct Answer: a) np.linalg.solve()
Explanation:
np.linalg.solve() solves the linear equation system ax = b.
Correct Answer: a) Masked Arrays
Explanation:
np.ma provides support for masked arrays, which can handle missing or invalid data.
Correct Answer: a) np.argpartition()
Explanation:
np.argpartition() performs an indirect partition using the algorithms specified by kind.
Correct Answer: a) 24
Explanation:
np.prod() returns the product of array elements over a given axis (1 * 2 * 3 * 4 = 24).
Correct Answer: a) np.linalg.matrix_rank()
Explanation:
np.linalg.matrix_rank() returns matrix rank using SVD matrix decomposition.
Correct Answer: a) Trims the leading and/or trailing zeros from a 1D array or sequence
Explanation:
np.trim_zeros() trims leading and trailing zeros from a 1D array or sequence.
Correct Answer: a) np.random.choice()
Explanation:
np.random.choice() generates a random sample from a given 1D array.
Correct Answer: a) A tuple of arrays, one for each dimension of the array
Explanation:
When called without x and y, np.where(condition) returns a tuple of arrays, one for each dimension, containing the indices where condition is true.
Related Posts
New
New
New

Python OOP MCQs
Object-Oriented Programming (OOP) in Python is a programming paradigm that uses classes and objects to model real world entities, promoting…
August 27, 2026By MCQs Generator

Python Control Flow MCQs
Control flow statements regulate the order in which individual code statements are evaluated and executed in a Python program. Python…
August 27, 2026By MCQs Generator

Python Variables & Data Types MCQs
Variables in Python act as dynamic references reserved in memory to store objects, operating without explicit data type declarations due…
August 27, 2026By MCQs Generator
Related Categories
New












AI & Data Science MCQ
5 topics
By MCQs Generator
New
Arts & Humanities MCQ
4 topics
By MCQs Generator
New
Civil Engineering MCQ
4 topics
By MCQs Generator
New
Commerce & Business MCQ
4 topics
By MCQs Generator
New
Competitive Exams MCQ
5 topics
By MCQs Generator
New
Electrical & Electronics Engineering MCQ
3 topics
By MCQs Generator
New
General Knowledge MCQ
2 topics
By MCQs Generator
New
General Science MCQ
4 topics
By MCQs Generator
New
Law & Judiciary MCQ
3 topics
By MCQs Generator
New
Mechanical Engineering MCQ
4 topics
By MCQs Generator
New
Medical & Health Sciences MCQ
4 topics
By MCQs Generator
New
Modern Tech Fields MCQ
3 topics
By MCQs Generator