Each question below shows the correct answer with a full explanation. Use these to build conceptual understanding before attempting a timed quiz.
Python for AIEasy
Q1. Which Python library is most commonly used for numerical computations in AI?
- A.Tkinter
- B.Flask
- C.NumPy✓ Correct
- D.Django
Explanation
NumPy is the fundamental library for numerical computing in Python, providing support for arrays and mathematical operations.
Report an error in this question
Python for AIEasy
Q2. What does pandas primarily provide?
- A.Network socket programming APIs
- B.Data structures for data analysis✓ Correct
- C.Web development framework tools
- D.Game development engine support
Explanation
Pandas provides DataFrame and Series data structures for efficient data manipulation and analysis.
Report an error in this question
Python for AIEasy
Q3. Which library is used for plotting graphs in Python?
- A.Pandas
- B.NumPy
- C.Matplotlib✓ Correct
- D.Scikit-learn
Explanation
Matplotlib is the standard Python library for creating static, animated, and interactive visualizations.
Report an error in this question
Python for AIEasy
Q4. How do you import NumPy with an alias?
- A.include numpy
- B.import np
- C.import numpy as num
- D.import numpy as np✓ Correct
Explanation
The convention is to import NumPy as np: import numpy as np.
Report an error in this question
Python for AIEasy
Q5. What is a Jupyter Notebook?
- A.An interactive computing environment for code and visualizations✓ Correct
- B.A production web server for hosting static site content
- C.A relational database for storing structured table records
- D.A lightweight plain text editor without any execution support
Explanation
Jupyter Notebook is an interactive web-based environment for writing and executing code, visualizing data, and documenting analysis.
Report an error in this question
Python for AIEasy
Q6. Which function creates a NumPy array?
- A.np.make()
- B.np.list()
- C.np.array()✓ Correct
- D.np.create()
Explanation
np.array() is used to create a NumPy array from a Python list or tuple.
Report an error in this question
Python for AIEasy
Q7. What does df.head() do in pandas?
- A.Sorts the DataFrame by column values
- B.Returns the last 5 rows of the frame
- C.Deletes the first row of the DataFrame
- D.Returns the first 5 rows of the DataFrame✓ Correct
Explanation
df.head() returns the first 5 rows of a pandas DataFrame by default.
Report an error in this question
Python for AIEasy
Q8. Which library provides machine learning algorithms in Python?
- A.Pillow
- B.Scikit-learn✓ Correct
- C.Seaborn
- D.Matplotlib
Explanation
Scikit-learn provides simple and efficient tools for data mining and machine learning in Python.
Report an error in this question
Python for AIEasy
Q9. What data type does pandas use for tabular data?
- A.List
- B.Dictionary
- C.DataFrame✓ Correct
- D.Array
Explanation
A pandas DataFrame is a 2-dimensional labeled data structure, similar to a spreadsheet or SQL table.
Report an error in this question
Python for AIEasy
Q10. Which operator is used for element-wise multiplication in NumPy?
- A.*✓ Correct
- B.//
- C.&
- D.@
Explanation
The * operator performs element-wise multiplication on NumPy arrays. The @ operator is for matrix multiplication.
Report an error in this question
Python for AIMedium
Q11. What is broadcasting in NumPy?
- A.A networking feature for sending data to multiple receivers
- B.Automatic expansion of arrays with different shapes for arithmetic✓ Correct
- C.A type of sorting algorithm for ordering array elements
- D.A logging mechanism for recording runtime error messages
Explanation
Broadcasting allows NumPy to perform arithmetic operations on arrays with different shapes by automatically expanding smaller arrays.
Report an error in this question
Python for AIMedium
Q12. Which scikit-learn class is used for train-test splitting?
- A.SplitData
- B.DataSplitter
- C.train_test_split✓ Correct
- D.TestTrainDivide
Explanation
sklearn.model_selection.train_test_split is used to split data into training and testing subsets.
Report an error in this question
Python for AIMedium
Q13. What does df.groupby() do in pandas?
- A.Renames columns using a provided mapping dict
- B.Sorts the DataFrame by index values in order
- C.Filters rows based on a boolean condition mask
- D.Groups data by one or more columns for aggregation✓ Correct
Explanation
groupby() splits data into groups based on column values, allowing aggregate operations on each group.
Report an error in this question
Python for AIMedium
Q14. Which pandas method fills missing values?
- A.fillna()✓ Correct
- B.isna()
- C.notna()
- D.dropna()
Explanation
fillna() replaces NaN/missing values with a specified value or method like forward fill or backward fill.
Report an error in this question
Python for AIMedium
Q15. What is a Python generator?
- A.A built-in immutable data type like a list
- B.A function that yields values lazily using yield✓ Correct
- C.A special class constructor for initialization
- D.A comparison-based sorting algorithm method
Explanation
A generator is a function that uses yield to produce values one at a time, enabling memory-efficient iteration.
Report an error in this question
Python for AIMedium
Q16. How do you perform matrix multiplication in NumPy?
- A.np.multiply(A, B) function✓ Correct
- B.A + B element-wise addition
- C.A * B element-wise product
- D.np.dot(A, B) or A @ B operator
Explanation
Matrix multiplication uses np.dot() or the @ operator. A * B performs element-wise multiplication.
Report an error in this question
Python for AIMedium
Q17. What does the pandas method .apply() do?
- A.Deletes specified rows from the DataFrame index
- B.Merges two DataFrames on a common column key
- C.Adds a new column to the end of a DataFrame
- D.Applies a function along an axis of a DataFrame✓ Correct
Explanation
apply() applies a function to each element, row, or column of a DataFrame or Series.
Report an error in this question
Python for AIMedium
Q18. Which visualization library is built on top of Matplotlib?
- A.Pygal
- B.Bokeh
- C.Seaborn✓ Correct
- D.Plotly
Explanation
Seaborn is built on Matplotlib and provides a high-level interface for drawing statistical graphics.
Report an error in this question
Python for AIMedium
Q19. What is the purpose of np.reshape()?
- A.To sort the elements of an array in ascending order
- B.To change the shape of an array without changing its data✓ Correct
- C.To filter elements of an array by a condition mask
- D.To delete selected elements from an existing array
Explanation
np.reshape() changes the dimensions of an array while preserving the same data and total number of elements.
Report an error in this question
Python for AIMedium
Q20. What does pickle do in Python?
- A.Manages relational database connections
- B.Performs numerical matrix calculations
- C.Creates interactive charts and plots
- D.Serializes and deserializes Python objects✓ Correct
Explanation
Pickle serializes Python objects to byte streams for saving/loading models and data structures.
Report an error in this question
Python for AIHard
Q21. What is the Global Interpreter Lock (GIL) in Python?
- A.A file system locking mechanism for preventing concurrent write access
- B.A garbage collection tool for automated memory resource management
- C.A cryptographic security feature for encrypting sensitive runtime data
- D.A mutex preventing multiple threads from executing Python bytecode simultaneously✓ Correct
Explanation
The GIL is a mutex in CPython that prevents multiple threads from executing Python bytecodes at the same time, limiting true parallelism.
Report an error in this question
Python for AIHard
Q22. Which tool is best for parallel processing of large datasets in Python?
- A.Flask
- B.Django
- C.Tkinter
- D.Dask✓ Correct
Explanation
Dask provides parallel computing capabilities and can handle datasets larger than memory by breaking them into smaller chunks.
Report an error in this question
Python for AIHard
Q23. What is the difference between deepcopy and copy in Python?
- A.deepcopy creates copies of nested objects recursively, copy does not✓ Correct
- B.copy is faster and creates a more thorough deep duplication
- C.deepcopy only works on list objects and not dictionaries
- D.They are completely identical in behavior and performance
Explanation
copy creates a shallow copy (references to nested objects are shared), while deepcopy recursively copies all nested objects.
Report an error in this question
Python for AIHard
Q24. In NumPy, what does np.einsum() do?
- A.Performs only element-wise operations on flat one-D arrays
- B.Performs Einstein summation for multi-dimensional array operations✓ Correct
- C.Creates identity matrices of a specified dimension size
- D.Calculates eigenvalues of a square matrix decomposition
Explanation
np.einsum() provides a concise way to express multi-dimensional array operations using Einstein summation convention.
Report an error in this question
Python for AIHard
Q25. What is vectorization in the context of NumPy?
- A.Converting natural language text into numeric vectors
- B.Performing operations on entire arrays instead of loops✓ Correct
- C.Creating scalable vector graphics for visualization
- D.A lossless data compression encoding technique
Explanation
Vectorization replaces explicit loops with array operations, leveraging optimized C implementations for significantly faster execution.
Report an error in this question
Python for AIHard
Q26. What does the __slots__ attribute do in Python classes?
- A.Defines abstract methods for interface contracts
- B.Enables multiple inheritance across class chains
- C.Restricts instance attributes and reduces memory usage✓ Correct
- D.Creates new class-level methods from descriptors
Explanation
__slots__ restricts which attributes instances can have and avoids the __dict__ overhead, reducing memory usage significantly.
Report an error in this question
Python for AIHard
Q27. Which library provides GPU-accelerated computing for Python ML?
- A.CuPy✓ Correct
- B.Pandas
- C.Matplotlib
- D.SciPy
Explanation
CuPy provides GPU-accelerated computing with a NumPy-compatible interface, enabling faster numerical computations on NVIDIA GPUs.
Report an error in this question
Python for AIHard
Q28. What is a context manager in Python and why is it useful in ML?
- A.It creates persistent database connections for data loading
- B.It manages resources using with statements ensuring proper cleanup✓ Correct
- C.It handles asynchronous network requests for API access
- D.It manages the training context of machine learning models
Explanation
Context managers (with statements) ensure proper resource acquisition and release, critical for managing file handles, GPU memory, and database connections in ML pipelines.
Report an error in this question
Python for AIHard
Q29. What is the purpose of __call__ in a Python class?
- A.Copies the object into a new reference
- B.Initializes a new class from a template
- C.Destroys the instance and frees memory
- D.Makes an instance callable like a function✓ Correct
Explanation
The __call__ method allows class instances to be called like functions, commonly used in PyTorch for defining model forward passes.
Report an error in this question
Python for AIHard
Q30. How does memory mapping (np.memmap) help in handling large datasets?
- A.It maps files to memory allowing access without loading the entire file✓ Correct
- B.It encrypts data at rest to ensure privacy and compliance
- C.It compresses data into smaller archive files for disk savings
- D.It duplicates data across servers for redundancy and backups
Explanation
Memory mapping allows accessing large files as if they were in memory without loading everything, enabling processing of datasets larger than available RAM.
Report an error in this question