NumPy arrays, dtypes, shapes, indexing, slicing, broadcasting, vectorization and linear algebra functions.
39 cards · basic cards · AI-written, checked twice. Edit anything.
- How do you create a NumPy array from a Python list?
Show answer
Use np.array() and pass the list as an argument
- What does np.zeros((3, 4)) create?
Show answer
A 3x4 array filled with zeros
- What does np.ones((2, 3)) create?
Show answer
A 2x3 array filled with ones
- What does np.arange(10) return?
Show answer
An array with integers from 0 to 9
- What does np.linspace(0, 1, 5) create?
Show answer
5 evenly spaced values from 0 to 1, inclusive
- What does np.random.rand(3, 2) return?
Show answer
A 3x2 array of random values between 0 and 1
- What is the dtype of an array?
Show answer
The data type of the array elements (int32, float64, etc.)
- How do you specify a dtype when creating an array?
Show answer
Pass dtype parameter, like np.array([1, 2, 3], dtype=float)
- How do you convert an array to a different dtype?
Show answer
Use the astype() method, like arr.astype(float)
- What is the difference between int32 and int64?
Show answer
int32 uses 32 bits for smaller range; int64 uses 64 bits and can store larger integers
- What does np.uint8 represent?
Show answer
Unsigned integer using 8 bits, range 0 to 255
- How do you check the dtype of an array?
Show answer
Access the dtype attribute, like arr.dtype
- What is the shape of a NumPy array?
Show answer
A tuple describing the size of the array along each dimension
- How do you get the shape of an array?
Show answer
Access the shape attribute, like arr.shape
- What does np.reshape(arr, (2, 5)) do?
Show answer
Reshapes array arr into a 2x5 array (must have same total elements)