
NumPy Fundamentals
Arrays, ndarray, indexing, slicing, broadcasting, vectorized operations, linear algebra
1What is an ndarray in NumPy?
What is an ndarray in NumPy?
Answer
An ndarray (N-dimensional array) is NumPy's fundamental data structure. It is a homogeneous multidimensional array, meaning all elements must be of the same type. This homogeneity enables very fast vectorized operations because data is stored contiguously in memory, unlike Python lists which store references to scattered objects.
2How to create a NumPy array containing the values [1, 2, 3, 4, 5]?
How to create a NumPy array containing the values [1, 2, 3, 4, 5]?
Answer
The np.array() function is the standard method for creating an ndarray from a Python sequence like a list or tuple. It converts the sequence into an optimized NumPy array. Other functions like np.arange() generate sequences but with different syntax (start, stop, step), and np.zeros()/np.ones() create arrays filled with specific values.
3Which function to use to create an array of 10 evenly spaced elements between 0 and 1?
Which function to use to create an array of 10 evenly spaced elements between 0 and 1?
Answer
np.linspace(0, 1, 10) creates exactly 10 evenly spaced values between 0 and 1, inclusive of both endpoints. It is ideal when the desired number of points is known. np.arange() uses a fixed step and may not include the endpoint. np.linspace() is preferred for intervals with a precise number of points, particularly for plotting or numerical integration calculations.
Which attribute provides the dimensions (shape) of a NumPy array?
How to create a 3x3 matrix filled with zeros?
+19 interview questions
Other Data Science & ML interview topics
Python Basics
Python Object-Oriented Programming
Python Data Structures
Git Fundamentals
SQL Basics
Pandas Basics
Jupyter & Google Colab
SQL Joins & Advanced Queries
Advanced Pandas
Visualization with Matplotlib & Seaborn
Interactive Visualizations with Plotly
Descriptive Statistics
Inferential Statistics
Web Scraping
BigQuery & Cloud Data
Feature Engineering
Supervised ML: Regression
Supervised ML: Classification
Decision Trees & Ensembles
Unsupervised ML
ML Pipelines & Validation
Time Series & Forecasting
Deep Learning Fundamentals
TensorFlow & Keras
CNN & Image Classification
RNN & Sequences
Transformers & Attention
NLP & Hugging Face
GenAI & LangChain
MLOps & Deployment
Master Data Science & ML for your next interview
Access all questions, flashcards, technical tests, code review exercises and interview simulators.
Start for free