PythonTutorials.net
Toggle Menu
Home
Online Python Compiler
Tutorials
Django
Flask
Scikit-Learn
NumPy
NLTK
Pillow
Blog
All Posts
NumPy Array Operations
Challenge your grasp of array manipulation,broadcasting,and indexing in NumPy.
1. What does np.arange(3, 15, 3) produce?
[3, 6, 9, 12]
[3, 6, 9, 12, 15]
[0, 3, 6, 9, 12]
[6, 9, 12]
2. What is the shape of the array created by np.array([[1,2,3], [4,5,6]])?
(2, 3)
(3, 2)
(6,)
(2, 2)
3. By default, what data type does np.zeros(5) return?
int
float64
bool
str
4. Given arr = np.array([[1,2],[3,4],[5,6]]), what is the result of np.sum(arr, axis=1)?
[3, 7, 11]
[9, 12]
[6, 15]
21
5. Which method modifies the original array in-place when changing its shape?
reshape()
resize()
ravel()
flatten()
6. Which of the following perform element-wise addition of two arrays `a` and `b`?
np.add(a, b)
a + b
np.sum(a, b)
a.concatenate(b)
7. Which of the following are attributes of a NumPy array?
shape
dtype
size
itemsize
8. When does NumPy broadcasting apply?
Arrays have the same shape
One array has a dimension of size 1
Arrays have different dimensions but compatible sizes
One array is a scalar
9. The expression `np.array([1,2,3]) + np.array([4,5])` is valid due to NumPy broadcasting.
True
False
10. The `flatten()` method returns a view of the original array.
True
False
11. What function computes the mean of an array? (full name)
12. What abbreviation is used for the function that concatenates arrays vertically? (lowercase)
13. What is the output of `np.array([[1,2,3],[4,5,6]])[1, ::2]`?
[4, 6]
[2, 6]
[1, 3]
[5]
14. What does `np.eye(4)` create?
4x4 identity matrix
4x1 column vector of ones
4x4 matrix of zeros
1D array of 4 ones
15. What is the result of `np.max(np.array([[5,1],[3,9]]), axis=0)`?
[5, 9]
[1, 3]
[5, 3]
9
16. Which functions return a new array (do not modify the original)?
reshape()
resize()
flatten()
ravel()
17. `np.dot(a, b)` is equivalent to matrix multiplication for 2D arrays `a` and `b`.
True
False
18. What is the data type of `np.array([1, 2.5, 3])`?
int64
float64
object
bool
19. What term describes the process of converting a multi-dimensional array to 1D? (starts with 'f')
20. Which of the following create a 2x3 array of zeros?
np.zeros((2, 3))
np.zeros(2, 3)
np.reshape(np.zeros(6), (2, 3))
np.array([[0,0,0], [0,0,0]])
Reset
Answered 0 of 0 — 0 correct