WorksheetsNumpy
Total questions: 66
Worksheet time: 1hrs 19mins
Which of the following creates a 1D array with elements [0, 1, 2, 3, 4]?
np.linspace(0, 5, 5)
np.arange(0, 5)
np.ones(5)
np.zeros(5)
What is the output of np.array([[1, 2], [3, 4]])[1, 0]?
1
2
3
4
How would you create a 2x3 array filled with random numbers between 0 and 1?
np.random.randint(0, 1, (2, 3))
np.random.rand(2, 3)
np.ones((2, 3))
np.zeros((2, 3))
Which function generates evenly spaced numbers over a specified interval?
np.arange
np.linspace
np.random.rand
np.zeros
To create an array of evenly spaced numbers between 0 and 10, we use the function
np.
(a)
The function np. (a) generates a matrix where all elements are zeros.
The shape of a NumPy array can be changed using the (a) method.
The function np. (a) generates an array of random numbers drawn from a standard normal distribution.
To create an identity matrix of size 4x4, the function (a) is used.
In NumPy, the function np. (a) returns the index of the maximum value in an array.
The function np. (a) can be used to join arrays along different axes.
np.arange(0, 11, 2) will generate the array [0, 1, 2, 3, 4, 5].
True
False
NumPy arrays are mutable, meaning their values can be changed after creation.
True
False
The method arr.reshape(3, 4) will return a reshaped version of the array, but the original array will remain unchanged unless reassigned.
True
False
The slicing arr[:3] includes the elements from index 0 to index 3, exclusive.
True
False
Broadcasting allows you to perform operations between arrays of different shapes without explicitly reshaping them.
True
False
The function np.ones((3, 3)) creates a 2D array of shape (3, 3) filled with zeros.
True
False
The np.random.randint(1, 100, 10) generates 10 random integers between 1 and 100 (inclusive).
True
False
What are the two main types of arrays in NumPy?
How do you create a NumPy array from a Python list? Provide an example.
What is the difference between np.arange and np.linspace?
What does np.eye do, and how is it useful?
How do you reshape an array in NumPy?
What is broadcasting in NumPy, and why is it important?
How can you concatenate two arrays along rows or columns?
Describe how you can use Boolean indexing in NumPy to filter elements from an array.
What are some common mathematical operations you can perform on NumPy arrays?
To create a NumPy array from a list, we use the function np. (a) .
The function np. (a) generates evenly spaced values within a specified range.
The np.eye(5) function creates a (a) matrix.
The method (a) is used to change the shape of an array.
The function np.random. (a) generates random numbers from a uniform distribution between 0 and 1.
A __________ is a 1D array, while a __________ is a 2D array in NumPy.
(a)
To concatenate two arrays along rows, use the function np. (a) .
The slicing notation arr[1:5] retrieves elements from index __________ to __________ (exclusive).
(a)
The function np. (a) returns the index of the maximum value in an array.
np.arange(0, 10, 2) generates the array [0, 2, 4, 6, 8].
True
false
NumPy arrays are immutable and cannot be changed after creation.
True
False
The function np.linspace(0, 5, 6) generates 6 evenly spaced numbers between 0 and 5.
True
False
np.zeros((3, 3)) creates a 1D array with three zeros.
True
False
Broadcasting allows NumPy arrays of different shapes to be used in arithmetic operations without explicit reshaping.
True
False
The slicing arr[:3] includes the element at index 3.
True
False
The function np.random.randint(1, 10, 5) generates 5 random integers between 1 and 10, inclusive.
True
False
The method reshape changes the shape of the array in-place.
True
False
An identity matrix is a square matrix with ones on the diagonal and zeros elsewhere.
True
False
Using Boolean indexing, you can filter elements of an array based on conditions.
True
False
How does the reshape method differ from changing the shape of an array directly?
What is the difference between np.random.rand and np.random.randn?
How can you ensure that a sliced array does not modify the original array in NumPy?
Describe how you would extract a subarray from a 3x3 matrix containing only the last two rows and the last two columns.
(a)
What is the output of np.arange(1, 10).reshape(3, 3)[1, 2]?
(a)
The function np.random. (a) generates random integers within a specified range.
To access the element in the second row and third column of a 2D array, you can use the notation arr[__________, __________].
(a)
The np. (a) function generates an array of evenly spaced values based on a step size.
The attribute arr. (a) is used to find the shape of an array.
The function np. (a) is used to join arrays along a specified axis.
To replace all elements in an array slice with the value 100, you can use the syntax arr[0:5] = (a) .
The slicing syntax arr[:, 1] selects all elements from the (a) column of a 2D array.
The function np.linspace(0, 1, 5) generates 4 evenly spaced numbers between 0 and 1.
True
False
The function np.random.randint(1, 5) can return the value 5.
True
False
You can use the axis parameter in np.concatenate to specify whether to concatenate along rows or columns.
True
False
Fancy indexing allows for selecting multiple rows or columns in any order.
True
False
What is the output of np.array([1, 2, 3, 4])[::-1]?
[1, 2, 3, 4]
[4, 3, 2, 1]
[2, 1, 4, 3]
[3, 2, 1, 4]
How can you create an array of 10 random integers between 50 and 100?
In NumPy, the term (a) refers to the ability to perform operations on arrays of different shapes
The function np. (a) can be used to generate an array of logarithmically spaced numbers.
