0% found this document useful (0 votes)
3 views10 pages

Numpy Prcatise Problems

The document is a comprehensive guide to practicing NumPy, containing 120 questions categorized by difficulty levels: beginner, intermediate, advanced, practical, and expert. It covers various concepts including array creation, indexing, operations, reshaping, random number generation, sorting, file I/O, and advanced manipulations. Each section includes specific tasks aimed at enhancing understanding and proficiency in using NumPy.

Uploaded by

muhammad ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views10 pages

Numpy Prcatise Problems

The document is a comprehensive guide to practicing NumPy, containing 120 questions categorized by difficulty levels: beginner, intermediate, advanced, practical, and expert. It covers various concepts including array creation, indexing, operations, reshaping, random number generation, sorting, file I/O, and advanced manipulations. Each section includes specific tasks aimed at enhancing understanding and proficiency in using NumPy.

Uploaded by

muhammad ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

NUMPY PRCATISE

PROBLEMS
BY
MUHAMMAD ALI
🧮 1. Basics & Arrays

 Import NumPy and print its version.

 Create a 1D, 2D, and 3D array.

 Check the shape, size, and dtype of an array.

 Convert a Python list to a NumPy array.

 Create arrays of zeros, ones, and a specific constant.

🔁 2. Indexing & Slicing

 Access specific elements in a 2D array.

 Slice the first 3 rows of a matrix.

 Reverse a 1D NumPy array.

 Set all odd numbers in an array to -1.

 Extract all elements greater than a certain value.

🧮 3. Array Operations

 Perform element-wise addition, subtraction, multiplication.

 Compute dot product of two matrices.

 Calculate mean, median, standard deviation of an array.

 Normalize an array (min-max scaling).

 Apply np.where() to conditionally replace values.

🔄 4. Reshaping & Stacking

 Reshape a 1D array into a 2D matrix.

 Flatten a multi-dimensional array.

 Stack two arrays vertically and horizontally.

 Split an array into equal-sized chunks.

 Expand or squeeze array dimensions.


5. Broadcasting & Vectorization

 Add a scalar to an entire array.

 Multiply a 2D matrix with a 1D row/column vector.

 Use broadcasting to normalize a matrix by row mean.

 Replace nested loops with vectorized operations.

 Create a distance matrix between points using broadcasting.

🧪 6. Random Numbers

 Generate an array of 10 random integers.

 Create a 2D array with random floats between 0 and 1.

 Fix the seed for reproducibility.

 Shuffle an array randomly.

 Sample from a normal distribution and plot histogram.

📊 7. Sorting & Searching

 Sort a 1D and 2D array.

 Get the indices that would sort an array.

 Search for a specific value in an array.

 Find the positions of max and min elements.

 Use np.unique() to get unique elements and their counts.

📚 8. Useful NumPy Functions

 Use np.linspace() and np.arange().

 Generate an identity matrix.

 Use np.tile() and np.repeat() for array replication.

 Use np.cumsum() and np.diff() on arrays.

 Create a checkerboard pattern using slicing.


📁 9. File I/O with NumPy

 Save a NumPy array to a .npy file.

 Load an array from a .npy file.

 Read a .csv file using np.loadtxt() or np.genfromtxt().

 Write a NumPy array to a .csv file.

 Load data skipping headers and specifying delimiters.

🧱 10. Advanced Operations

 Create a structured array with named columns.

 Mask invalid or NaN entries using np.isnan().

 Use np.linalg to compute matrix inverse and determinant.

 Perform Singular Value Decomposition (SVD).

 Simulate 100 coin tosses and count heads/tails.

Would you like this as a Word document like the original? I can generate and download it for
you.

4o

You said:

no give me atleast 120 question ranging from beginners to advanced to teach me numpy
covering all concepts

ChatGPT said:

Absolutely — here is a comprehensive list of 120 NumPy questions, grouped by difficulty level
and concept, to take you from beginner to advanced mastery. These are designed to mirror your
previous Python practice document, with NumPy-focused problems instead.

🟢 BEGINNER LEVEL

1. Basics & Array Creation

1. Import NumPy and print its version.

2. Create a 1D NumPy array from a list.

3. Create a 2D NumPy array of shape (3,3) with values from 1 to 9.


4. Generate an array of 10 zeros.

5. Generate an array of 10 ones.

6. Create an array filled with the number 7.

7. Create an array of 10 random integers between 0 and 100.

8. Create an array of even numbers from 2 to 20.

9. Create a 3x3 identity matrix.

10. Generate 5 values between 0 and 1 using linspace().

2. Data Types & Inspection

11. Check the data type of an array.

12. Convert an array of floats to integers.

13. Create a complex number array.

14. Get the shape, size, and number of dimensions of an array.

15. Change the data type of a NumPy array.

3. Indexing & Slicing

16. Access the first 3 elements of a 1D array.

17. Slice the middle row of a 3x3 array.

18. Reverse a 1D array.

19. Set all odd numbers in an array to -1.

20. Replace all negative values in an array with 0.

4. Basic Array Operations

21. Add two arrays element-wise.

22. Subtract two arrays.

23. Multiply two arrays element-wise.

24. Divide one array by another.

25. Square every element of an array.

🟡 INTERMEDIATE LEVEL

5. Array Reshaping & Flattening

26. Reshape a 1D array into a 2x5 matrix.


27. Flatten a multi-dimensional array into 1D.

28. Convert a row vector to column vector.

29. Expand dimensions of a 1D array to 2D.

30. Squeeze a 3D array into 2D.

6. Stacking & Splitting

31. Stack two arrays vertically.

32. Stack two arrays horizontally.

33. Split an array into 3 equal parts.

34. Split a 2D array into columns.

35. Concatenate arrays using np.concatenate.

7. Statistical Operations

36. Calculate the mean of an array.

37. Find the median of an array.

38. Compute the standard deviation.

39. Find the minimum and maximum values.

40. Find the index of the maximum element.

8. Conditional Logic & Masking

41. Replace all elements greater than 10 with 10.

42. Create a boolean mask for elements > 5.

43. Extract elements that satisfy a condition.

44. Use np.where() to replace negative values.

45. Count the number of positive elements.

9. Random Number Generation

46. Generate 5 random floats between 0 and 1.

47. Create a 3x3 matrix of random integers (0–10).

48. Use np.random.seed() to fix randomness.

49. Shuffle a 1D array.

50. Simulate 100 coin tosses using 0 and 1.


🔵 ADVANCED LEVEL

10. Broadcasting

51. Add a 1D array to each row of a 2D array.

52. Multiply a 1D array with each column of a 2D array.

53. Normalize a 2D matrix row-wise using broadcasting.

54. Compute a distance matrix between points.

55. Subtract column means from a matrix.

11. Mathematical Functions

56. Use np.exp() and np.log() on an array.

57. Apply np.sin() and np.cos() to angles in radians.

58. Round off all elements to 2 decimal places.

59. Clip values of an array between 0 and 1.

60. Compute factorial of elements using np.vectorize().

12. Linear Algebra

61. Compute dot product of two vectors.

62. Perform matrix multiplication using @ and dot().

63. Transpose a 2D array.

64. Find inverse of a square matrix.

65. Compute determinant of a matrix.

13. Advanced Indexing & Fancy Indexing

66. Select elements using a list of indices.

67. Replace specific elements at given positions.

68. Get non-zero elements using np.nonzero().

69. Extract top 5 largest values using argpartition.

70. Convert indices into 2D coordinates.

14. Set Operations

71. Find union of two arrays.

72. Compute intersection of arrays.

73. Get difference of two arrays.


74. Find unique values and their counts.

75. Check if two arrays are equal.

🟣 PRACTICAL / USEFUL SNIPPETS

15. Real-world Datasets & Files

76. Load a CSV file using np.loadtxt().

77. Load data using np.genfromtxt() with missing values.

78. Save an array to a .npy file.

79. Save multiple arrays using np.savez().

80. Write a NumPy array to CSV.

16. Sorting & Searching

81. Sort a 1D array in ascending order.

82. Sort rows of a 2D array.

83. Get indices that would sort an array.

84. Use searchsorted() for insertion index.

85. Find the position of the max value using argmax().

17. Structured Arrays

86. Create a structured array with fields (name, age, score).

87. Sort structured array by one field.

88. Filter structured array where score > 80.

89. Add a new field to an existing structured array.

90. Read structured data from CSV.

18. Masking & NaN Handling

91. Create an array with NaNs and check them.

92. Replace NaNs with 0.

93. Drop NaN values using logical indexing.

94. Count NaN entries in an array.

95. Use np.isnan() with masking.


🔴 EXPERT LEVEL

19. Performance Optimization

96. Time a for-loop vs. vectorized NumPy code.

97. Use np.vectorize() to speed up custom functions.

98. Compare np.dot() vs matrix multiplication using @.

99. Benchmark random vs linspace vs arange.

100. Avoid loops using advanced slicing.

20. Simulations & Modeling

101. Simulate rolling 2 dice 1000 times and sum results.

102. Model radioactive decay using exponential function.

103. Generate synthetic 2D data for classification.

104. Simulate random walk in 1D.

105. Compute probability distribution from samples.

21. Advanced Manipulations

106. Generate a checkerboard pattern using slicing.

107. Create a diagonal matrix with values from 1 to 5.

108. Shift all elements in an array to the right.

109. Create a 10x10 array with a border of 1 and 0 inside.

110. Pad a matrix with zeros on all sides.

22. Miscellaneous Power Features

111. Count frequency of elements in an array.

112. Use np.apply_along_axis() to apply function row-wise.

113. Generate rolling averages over a 1D array.

114. Tile a pattern across a matrix.

115. Find all pairs of rows that are duplicates.

23. Math & Statistics Use Cases

116. Compute correlation coefficient between two arrays.

117. Generate a covariance matrix.

118. Fit a linear regression using matrix operations.


119. Create a histogram from data using np.histogram().

120. Implement z-score normalization on a dataset.

You might also like