0% found this document useful (0 votes)
2 views12 pages

Numpy

The document contains a series of questions and answers related to NumPy, a popular Python library for numerical computing. It covers basic to advanced topics, including array creation, manipulation, mathematical operations, and functions for linear algebra. Each question is multiple-choice, providing the correct answer alongside the options.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views12 pages

Numpy

The document contains a series of questions and answers related to NumPy, a popular Python library for numerical computing. It covers basic to advanced topics, including array creation, manipulation, mathematical operations, and functions for linear algebra. Each question is multiple-choice, providing the correct answer alongside the options.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

1. **What does NumPy stand for?

**

- A) Numerical Python

- B) Number Python

- C) Numerical Pylab

- D) None of the above

**Answer:** A) Numerical Python

2. **Which of the following is the correct way to import NumPy?**

- A) `import numpy as np`

- B) `import np`

- C) `import numpy as nump`

- D) `import numpy`

**Answer:** A) `import numpy as np`

3. **What function is used to create an array in NumPy?**

- A) `np.arr()`

- B) `np.array()`

- C) `np.create_array()`

- D) `np.make_array()`

**Answer:** B) `np.array()`

4. **Which function is used to generate evenly spaced values within a given interval?**

- A) `np.linspace()`

- B) `np.arrange()`

- C) `np.arange()`

- D) `np.spaced()`

**Answer:** C) `np.arange()`

5. **What is the default data type of elements in a NumPy array?**

- A) `int`
- B) `float`

- C) `str`

- D) `bool`

**Answer:** B) `float`

6. **What function creates an array of all zeros?**

- A) `np.zeros()`

- B) `np.ones()`

- C) `np.zero()`

- D) `np.full()`

**Answer:** A) `np.zeros()`

7. **How do you check the shape of a NumPy array?**

- A) `array.size()`

- B) `array.shape()`

- C) `array.shape`

- D) `array.size`

**Answer:** C) `array.shape`

8. **How do you change the shape of an existing NumPy array?**

- A) `np.reshape(array)`

- B) `array.reshape()`

- C) `np.shape(array)`

- D) `array.change_shape()`

**Answer:** B) `array.reshape()`

9. **Which function creates an identity matrix?**

- A) `np.matrix()`

- B) `np.ones()`

- C) `np.identity()`

- D) `np.eye()`
**Answer:** D) `np.eye()`

10. **What function concatenates two NumPy arrays along a specified axis?**

- A) `np.concat()`

- B) `np.vstack()`

- C) `np.hstack()`

- D) `np.concatenate()`

**Answer:** D) `np.concatenate()`

11. **What is the result of `np.add([1, 2], [3, 4])`?**

- A) `[1, 2, 3, 4]`

- B) `[4, 6]`

- C) `6`

- D) `[1, 5, 9]`

**Answer:** B) `[4, 6]`

12. **Which function is used to return the maximum element of an array?**

- A) `np.max()`

- B) `np.min()`

- C) `np.argmax()`

- D) `np.maximum()`

**Answer:** A) `np.max()`

13. **Which method sorts an array in NumPy?**

- A) `np.order()`

- B) `np.sort()`

- C) `np.arrange()`

- D) `np.list_sort()`

**Answer:** B) `np.sort()`

14. **What function returns the sum of all elements in a NumPy array?**
- A) `np.add()`

- B) `np.sum()`

- C) `np.total()`

- D) `np.total_sum()`

**Answer:** B) `np.sum()`

15. **What does the `axis` parameter control in many NumPy functions?**

- A) The function behavior

- B) The size of the array

- C) The dimension along which to apply the function

- D) The type of array

**Answer:** C) The dimension along which to apply the function

---

### **Intermediate Level (16–30)**

16. **How do you create a NumPy array with random values between 0 and 1?**

- A) `np.random.random()`

- B) `np.random.rand()`

- C) `np.random.rnd()`

- D) `np.random.randint()`

**Answer:** B) `np.random.rand()`

17. **Which function will return the dot product of two arrays?**

- A) `np.multiply()`

- B) `np.dot()`

- C) `np.cross()`

- D) `np.matmul()`

**Answer:** B) `np.dot()`
18. **What is the output of `np.arange(1, 10, 3)`?**

- A) `[1, 3, 6]`

- B) `[1, 4, 7]`

- C) `[1, 4, 8]`

- D) `[1, 4, 9]`

**Answer:** B) `[1, 4, 7]`

19. **Which of the following function computes the inverse of a matrix?**

- A) `np.inverse()`

- B) `np.linalg.inv()`

- C) `np.inv()`

- D) `np.linalg.solve()`

**Answer:** B) `np.linalg.inv()`

20. **Which function is used to find the determinant of a matrix?**

- A) `np.determinant()`

- B) `np.linalg.det()`

- C) `np.linalg.detm()`

- D) `np.det()`

**Answer:** B) `np.linalg.det()`

21. **What function will return the cumulative sum of elements along a given axis?**

- A) `np.sum_cumulative()`

- B) `np.cumsum()`

- C) `np.add_cum()`

- D) `np.cumprod()`

**Answer:** B) `np.cumsum()`

22. **How do you find the standard deviation of a NumPy array?**

- A) `np.std()`

- B) `np.variance()`
- C) `np.sqrt()`

- D) `np.stdev()`

**Answer:** A) `np.std()`

23. **Which of the following function finds the index of the minimum value in an array?**

- A) `np.min()`

- B) `np.argmin()`

- C) `np.index_min()`

- D) `np.arg_index()`

**Answer:** B) `np.argmin()`

24. **What function will flatten a multi-dimensional array to one dimension?**

- A) `np.flat()`

- B) `np.reshape(1D)`

- C) `np.ravel()`

- D) `np.flatten()`

**Answer:** D) `np.flatten()`

25. **Which function can be used to stack arrays vertically?**

- A) `np.vstack()`

- B) `np.hstack()`

- C) `np.concatenate(1)`

- D) `np.concat_v()`

**Answer:** A) `np.vstack()`

26. **How do you transpose a matrix in NumPy?**

- A) `np.transpose()`

- B) `array.transpose()`

- C) `np.flip()`

- D) `array.T`

**Answer:** D) `array.T`
27. **What does the `np.all()` function check for in an array?**

- A) If all values are zero

- B) If all values are non-zero

- C) If all elements satisfy a condition

- D) If all values are integers

**Answer:** C) If all elements satisfy a condition

28. **How do you add a new axis to a NumPy array?**

- A) `np.addaxis()`

- B) `np.newaxis()`

- C) `np.expand_dims()`

- D) `np.add_dimension()`

**Answer:** C) `np.expand_dims()`

29. **What does `np.random.randint(1, 10, size=(3, 3))` generate?**

- A) A 1D array of integers from 1 to 10

- B) A 2D array of size 3x3 with integers between 1 and 10

- C) A 2D array of size 3x3 with integers between 0 and 9

- D) A 3D array

**Answer:** B) A 2D array of size 3x3 with integers between 1 and 10

30. **What does `np.sqrt(array)` do?**

- A) Returns the

square root of each element in the array

- B) Squares each element in the array

- C) Returns the sum of the square roots

- D) Returns an array of integers

**Answer:** A) Returns the square root of each element in the array


---

### **Advanced Level (31–50)**

31. **Which method is used to solve a system of linear equations in NumPy?**

- A) `np.linalg.solve()`

- B) `np.solve()`

- C) `np.linear_solve()`

- D) `np.linalg.equation()`

**Answer:** A) `np.linalg.solve()`

32. **What does `np.random.seed()` do?**

- A) Randomizes the array generation

- B) Controls the random number generator for reproducibility

- C) Generates random seeds

- D) Sets the seed value

**Answer:** B) Controls the random number generator for reproducibility

33. **Which of the following NumPy functions returns the eigenvalues and eigenvectors of a matrix?
**

- A) `np.linalg.eig()`

- B) `np.eigen()`

- C) `np.linalgeigen()`

- D) `np.linalg.ev()`

**Answer:** A) `np.linalg.eig()`

34. **What function computes the outer product of two arrays?**

- A) `np.outer()`

- B) `np.outerprod()`

- C) `np.prod_outer()`

- D) `np.multiply()`
**Answer:** A) `np.outer()`

35. **Which of the following computes the Moore-Penrose inverse of a matrix?**

- A) `np.pinv()`

- B) `np.inv()`

- C) `np.linalg.mpinv()`

- D) `np.inverse()`

**Answer:** A) `np.pinv()`

36. **What function will return the singular value decomposition of a matrix?**

- A) `np.svd()`

- B) `np.decompose()`

- C) `np.linsvd()`

- D) `np.linalg.svd()`

**Answer:** D) `np.linalg.svd()`

37. **Which function computes the QR decomposition of a matrix?**

- A) `np.linalg.qr()`

- B) `np.qr_decompose()`

- C) `np.qr()`

- D) `np.decomp_qr()`

**Answer:** A) `np.linalg.qr()`

38. **How do you find the rank of a matrix in NumPy?**

- A) `np.rank()`

- B) `np.linalg.matrix_rank()`

- C) `np.linalg.rank()`

- D) `np.matrix_rank()`

**Answer:** B) `np.linalg.matrix_rank()`

39. **What function is used to check if a matrix is singular?**


- A) `np.is_singular()`

- B) `np.linalg.det() == 0`

- C) `np.matrix_singular()`

- D) `np.linalg.is_singular()`

**Answer:** B) `np.linalg.det() == 0`

40. **Which NumPy function is used for element-wise multiplication of two arrays?**

- A) `np.matmul()`

- B) `np.dot()`

- C) `np.multiply()`

- D) `np.prod()`

**Answer:** C) `np.multiply()`

41. **How can you calculate the Frobenius norm of a matrix?**

- A) `np.linalg.norm()`

- B) `np.norm_frob()`

- C) `np.frobenius()`

- D) `np.matrix_norm()`

**Answer:** A) `np.linalg.norm()`

42. **Which function will return the cross product of two vectors?**

- A) `np.dot()`

- B) `np.cross()`

- C) `np.prod()`

- D) `np.outer()`

**Answer:** B) `np.cross()`

43. **What will be the result of `np.tril(np.ones((3, 3)))`?**

- A) A lower triangular matrix of ones

- B) A diagonal matrix of ones

- C) An upper triangular matrix of ones


- D) An identity matrix

**Answer:** A) A lower triangular matrix of ones

44. **What function is used to calculate the product of array elements over a given axis?**

- A) `np.prod()`

- B) `np.product()`

- C) `np.multiply()`

- D) `np.cumprod()`

**Answer:** A) `np.prod()`

45. **Which function computes the covariance matrix of a set of data in NumPy?**

- A) `np.cov()`

- B) `np.covar()`

- C) `np.covmat()`

- D) `np.covar_matrix()`

**Answer:** A) `np.cov()`

46. **How can you find the number of non-zero elements in an array?**

- A) `np.count_nonzero()`

- B) `np.nonzero()`

- C) `np.count_zeros()`

- D) `np.sum_nonzero()`

**Answer:** A) `np.count_nonzero()`

47. **What does `np.r_` do in NumPy?**

- A) Joins arrays row-wise

- B) Joins arrays column-wise

- C) Creates a range of values

- D) Computes the rank of a matrix

**Answer:** A) Joins arrays row-wise


48. **Which NumPy function will return the indices of the non-zero elements in an array?**

- A) `np.nonzero()`

- B) `np.arg_nonzero()`

- C) `np.count_nonzero()`

- D) `np.nonzero_idx()`

**Answer:** A) `np.nonzero()`

49. **How can you create a structured array in NumPy with named fields?**

- A) `np.dtype()`

- B) `np.structured()`

- C) `np.record()`

- D) `np.array(named=True)`

**Answer:** A) `np.dtype()`

50. **What function is used to stack arrays along a new dimension in NumPy?**

- A) `np.stack()`

- B) `np.concatenate()`

- C) `np.vstack()`

- D) `np.newstack()`

**Answer:** A) `np.stack()`

You might also like