NumPy and Pandas Functions Quiz

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

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?

  • [1, 2, 3]
  • [3, 6]
  • [6, 15]
  • [5, 7, 9] (correct)

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?

<p>Generates 3 random integers between 1 and 9 (A)</p> Signup and view all the answers

Given a = np.array([1, 2, 3]) and b = np.array([2, 2, 2]), what will np.dot(a, b) output?

<p>12 (B)</p> Signup and view all the answers

Which method, given an array arr, can be used to insert a new column at a specific index?

<p><code>np.insert(arr, index, values, axis=1)</code> (B)</p> Signup and view all the answers

Given df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]}), what does df['B'].sum() return?

<p>15 (D)</p> Signup and view all the answers

Given a DataFrame df, how can you select all rows where column 'A' is greater than 2 and column 'B' is less than 5?

<p><code>df[(df['A'] &gt; 2) &amp; (df['B'] &lt; 5)]</code> (D)</p> Signup and view all the answers

Flashcards

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?

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?

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?

The np.random.random() function generates random numbers between 0 and 1 (exclusive).

Signup and view all the flashcards

What does np.dot(a, b) do in NumPy?

The np.dot(a, b) function calculates the dot product of two NumPy arrays, a and b, which is the sum of the products of corresponding elements.

Signup and view all the flashcards

How do you add a row to a NumPy array?

The np.append(a, new_row, axis=0) function adds a new row (new_row) to the end of a NumPy array (a).

Signup and view all the flashcards

How do you sum values in a Pandas DataFrame column?

The df['A'].sum() function calculates the sum of values in the column 'A' of a Pandas DataFrame.

Signup and view all the flashcards

How do you check for missing values in a Pandas DataFrame?

The df.isnull() function checks for missing values (NaNs) in a Pandas DataFrame and returns a DataFrame with Boolean values indicating missing data.

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'), or df[df['A'] > 2]

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

More Like This

Numpy Mastery Quiz
5 questions

Numpy Mastery Quiz

UnequivocalGreenTourmaline avatar
UnequivocalGreenTourmaline
NumPy Fundamentals Quiz
10 questions
Week 2: Introduction to NumPy
37 questions
NumPy Arrays and Linear Algebra
27 questions
Use Quizgecko on...
Browser
Browser