Creating a NumPy Array

Last Updated :
Discuss
Comments

Question 1

Which function is used to create a NumPy array from a list?

  • A

    np.create()

  • B

    np.array()

  • C

    np.list()

  • D

    np.arraylist()

Question 2

Which of the following code snippets will create a NumPy array with the values [1,2,3,4]?

  • A

    np.array([1, 2, 3, 4])

  • B

    np.create([1, 2, 3, 4])

  • C

    np.array([1, 2, 3, 4], type=int)

  • D

    np.list([1, 2, 3, 4])

Question 3

Given the following code, what will be the output?

Python
import numpy as np
arr = np.array([1, 2, 3, 4], dtype=float)
print(arr)


  • A

    [1 2 3 4]

  • B

    [1. 2. 3. 4]

  • C

    [1.0 2.0 3.0 4.0]

  • D

    Error

Question 4

What will be the output of the following code?

Python
import numpy as np
arr = np.array([1, 2, 3, 4])
arr = arr.astype(float)
print(arr)


  • A

    [1 2 3 4]

  • B

    [1.0 2.0 3.0 4.0]

  • C

    [1. 2. 3. 4. ]

  • D

    Error

Question 5

What will be the output of this code?

Python
import numpy as np
arr = np.array([[1, 2], [3, 4]])
print(arr.shape)


  • A

    (2, 2)

  • B

    (1, 4)

  • C

    (4, )

  • D

    (2, 1)

Question 6

Which of the following will create a 3x3 matrix filled with zeros?

  • A

    np.zeros(3, 3)

  • B

    np.array([[0, 0, 0], [0, 0, 0], [0, 0, 0]])

  • C

    np.zeros((3, 3))

  • D

    np.zeros([3, 3])

Question 7

What will be the output of the following code?

Python
import numpy as np
arr = np.array([1, 2, 3, 4])
print(np.ndim(arr))


  • A

    1

  • B

    4

  • C

    None

  • D

    2

Question 8

Which method is used to create an array of equally spaced values?

  • A

    np.linspace()

  • B

    np.arrange()

  • C

    np.array()

  • D

    np.arrange()

Question 9

What will be the output of the following code?

Python
import numpy as np
arr = np.array([1, 2, 3, 4, 5])
print(np.sum(arr))


  • A

    15

  • B

    10

  • C

    5

  • D

    1

Question 10

What is the correct way to create a 4x4 identity matrix in NumPy?

  • A

    np.eye(4)

  • B

    np.array([1, 0, 0, 0], [0, 1, 0, 0],[0, 0, 1, 0], [1, 0, 0, 1]]

  • C

    np.identity(4)

  • D

    Both a and b

Tags:

There are 10 questions to complete.

Take a part in the ongoing discussion