What is a NumPy array?
a) A grid of values, all of the same type, indexed by a tuple of non-negative integers
b) A list of mixed data types
c) A dictionary of key-value pairs
d) A single value stored in memory
Answer:
a) A grid of values, all of the same type, indexed by a tuple of non-negative integers
Explanation:
A NumPy array is a grid of values, all of the same type, that can be indexed by a tuple of non-negative integers. It is the core data structure in NumPy and supports multidimensional arrays (also known as tensors) that can hold elements of a single data type.
import numpy as np
# Creating a 2D NumPy array
arr = np.array([[1, 2, 3], [4, 5, 6]])
print(arr)
In this example, a 2D NumPy array is created, representing a grid of values. NumPy arrays are highly efficient for numerical computations due to their homogeneous data type and fixed size.
NumPy arrays are central to numerical computing in Python, offering various functionalities like slicing, indexing, and broadcasting, which make complex mathematical operations simpler and more efficient.