Python Numpy Quiz

Last Updated :
Discuss
Comments

Question 1

How can you calculate the element-wise square root of a NumPy array arr?

  • A

    np.sqrt(arr)

  • B

    arr.sqrt()

  • C

    np.square_root(arr)

  • D

    arr.square_root()

Question 2

Question: How can you save a Pandas DataFrame to a CSV file?

  • A

    df.save_csv("filename.csv")

  • B

    df.write_csv("filename.csv")

  • C

    df.to_csv("filename.csv")

  • D

    df.export_csv("filename.csv")

Question 3

How can you perform a time-based resampling in Pandas?

  • A

    df.resample()

  • B

    df.time_resample()

  • C

    df.groupby("time_column").resample()

  • D

    df.time_groupby().resample()

Question 4

What is the purpose of the melt() function in Pandas?

  • A

    To melt a DataFrame into a longer format

  • B

    To create a melted cheese plot

  • C

    To melt a DataFrame into a wider format

  • D

    To melt a DataFrame into a binary format

Question 5

How can you handle duplicate values in a Pandas DataFrame?

  • A

    Use the df.drop_duplicates() method

  • B

    Use the df.remove_duplicates() method

  • C

    Use the df.drop_duplicate_rows() method

  • D

    Use the df.eliminate_duplicates() method

Question 6

How can you handle missing values in a Pandas DataFrame?

  • A

    Use df.fillna(value) to replace missing values

  • B

    Use df.dropna() to remove rows with missing values

  • C

    Both A and B

  • D

    Neither A nor B

Question 7

How can you merge two DataFrames in Pandas?

  • A

    df.concat()

  • B

    df.join()

  • C

    df.merge()

  • D

    df.combine()

Question 8

Write code to normalize a NumPy array arr by scaling its values to be between 0 and 1.

  • A

    normalized_arr = (arr - arr.min()) / (arr.max() - arr.min())

  • B

    normalized_arr = np.scale(arr)

  • C

    normalized_arr = arr.normalize()

  • D

    normalized_arr = (arr - arr.mean()) / arr.std()

Question 9

How can you calculate the mean along a specific axis of a 2D NumPy array arr?

  • A

    mean_values = np.mean(arr, axis=1)

  • B

    mean_values = arr.mean(axis=0)

  • C

    mean_values = np.average(arr, axis=1)

  • D

    mean_values = arr.mean(axis=2)

Question 10

Write code to find the intersection of two NumPy arrays a and b.

  • A

    intersection = np.intersect(a, b)

  • B

    intersection = np.common(a, b)

  • C

    intersection = np.intersect1d(a, b)

  • D

    intersection = a.intersection(b)

There are 25 questions to complete.

Take a part in the ongoing discussion