Podcast
Questions and Answers
What does np.arange(7)
return?
What does np.arange(7)
return?
- [0, 1, 2, 3, 4, 5, 6] (correct)
- [1, 2, 3, 4, 5, 6, 7]
- [1, 2, 3, 4, 5, 6]
- [0, 2, 4, 6]
Given arr = np.array([[1, 2, 3], [4, 5, 6]])
, what will arr.sum(axis=0)
output?
Given arr = np.array([[1, 2, 3], [4, 5, 6]])
, what will arr.sum(axis=0)
output?
- [1, 2, 3]
- [3, 6]
- [6, 15]
- [5, 7, 9] (correct)
Which NumPy function will generate a 4x4 matrix with all elements as zeros?
Which NumPy function will generate a 4x4 matrix with all elements as zeros?
- np.ones((4, 4))
- np.zeros((4, 4)) (correct)
- np.identity(4)
- np.diag([0, 0, 0, 0])
What does np.random.randint(1, 10, 3)
do?
What does np.random.randint(1, 10, 3)
do?
Given a = np.array([1, 2, 3])
and b = np.array([2, 2, 2])
, what will np.dot(a, b)
output?
Given a = np.array([1, 2, 3])
and b = np.array([2, 2, 2])
, what will np.dot(a, b)
output?
Which method, given an array arr
, can be used to insert a new column at a specific index?
Which method, given an array arr
, can be used to insert a new column at a specific index?
Given df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
, what does df['B'].sum()
return?
Given df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
, what does df['B'].sum()
return?
Given a DataFrame df
, how can you select all rows where column 'A' is greater than 2 and column 'B' is less than 5?
Given a DataFrame df
, how can you select all rows where column 'A' is greater than 2 and column 'B' is less than 5?
Flashcards
What does np.arange(5)
return in NumPy?
What does np.arange(5)
return in NumPy?
The np.arange(5)
function in NumPy generates a sequence of numbers starting from 0 (inclusive) and ending at 5 (exclusive), incrementing by 1.
How does arr.sum(axis=1)
work in NumPy?
How does arr.sum(axis=1)
work in NumPy?
The arr.sum(axis=1)
function calculates the sum of elements along the rows (axis=1) of a NumPy array. In this case, it adds the elements of each row, returning an array with the sum of each row.
How do you create a 3x3 identity matrix in NumPy?
How do you create a 3x3 identity matrix in NumPy?
The np.identity(3)
function creates a 3x3 identity matrix, which has 1s along the main diagonal and 0s elsewhere.
Which NumPy function produces random numbers between 0 and 1?
Which NumPy function produces random numbers between 0 and 1?
Signup and view all the flashcards
What does np.dot(a, b)
do in NumPy?
What does np.dot(a, b)
do in NumPy?
Signup and view all the flashcards
How do you add a row to a NumPy array?
How do you add a row to a NumPy array?
Signup and view all the flashcards
How do you sum values in a Pandas DataFrame column?
How do you sum values in a Pandas DataFrame column?
Signup and view all the flashcards
How do you check for missing values in a Pandas DataFrame?
How do you check for missing values in a Pandas DataFrame?
Signup and view all the flashcards
Study Notes
NumPy Functions
np.arange(5)
returns[0, 1, 2, 3, 4]
sum(axis=1)
calculates the row-wise sums in a 2D array
NumPy Identity Matrix
np.identity(3)
generates a 3x3 identity matrix
Random Number Generation
np.random.random()
generates random numbers between 0 and 1
NumPy Array Operations
np.append()
adds a new row to the end of a NumPy array
Pandas DataFrame Operations
-
The
sum()
method on a Pandas Series calculates the sum of the values. -
df.isnull()
checks for missing or NaN values in a DataFrame. -
df.groupby()
groups data based on column values, enabling aggregation and transformation -
df.dropna()
removes rows containing missing values. -
To select rows where 'A' is greater than 2, use
df.loc[df['A'] > 2]
,df.query('A > 2')
, ordf[df['A'] > 2]
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.