CORRECT Answers
Since NumPy arrays can only have one data type in an array the following code would cause a
Run-time error (not work).
import numpy as np
arr_a = np.array([1, "2", 0]) - CORRECT ANSWER - False
The following code creates a NumPy list of integers.
import numpy as np
arr_a = np.array([1, 2, 0.0]) - CORRECT ANSWER - False
import numpy as np
#Python Lists:
a = [1, 3, 5, 7, 9]
b = [2, 4, 6, 8, 10]
c=a+b
#NumPy Arrays:
an = np.array(a)
bn = np.array(b)
ac = an + bn
print(ac) - CORRECT ANSWER - [1, 3, 5, 7, 9, 2, 4, 6, 8, 10]
[ 3 7 11 15 19]
If we have a 1-diminsional array we can convert it to a 2-dimensional array using what method?
- CORRECT ANSWER - np.reshape()
, To determine the dimensions of a NumPy array we can use what code? - CORRECT
ANSWER - arr.ndim
The following code would be considered what kind of NumPy array?
import numpy as np
arr = np.array([[1, 3, 5],
[2, 4, 6],
[5,6,7]]) - CORRECT ANSWER - 2-dimensional
The following code would cause an run-time error (would not work).
a = np.array([1, 3, 5])
b = np.array([6]) - CORRECT ANSWER - False
To fill a one-dimensional NumPy array of 10 elements with all zeros we can use - CORRECT
ANSWER - np.zeros(0,0)
To create a 2-dimensional array of random numbers we could use the following code -
CORRECT ANSWER - np.random.randint(0, 10, (3, 3))
To print out the first row of the following NumPy array I could use
import numpy as np
b = np.array([[5, 3, 1],
[2, 4, 6]]) - CORRECT ANSWER - More than one of these options would work:
print(b[0, :])
print(b[:])
print(b(0))
print(b[0])