4.4.6.Graded Quiz Numpy in Python - sj50179/IBM-Data-Science-Professional-Certificate GitHub Wiki

LATEST SUBMISSION GRADE 100%

Question 1

What is the result of the following lines of code?

a=np.array([1,1,1,1,1])
b=np.array([2,2,2,2,2])
a*b
  • 0
  • array([0, 0, 0, 0, 0])
  • array([2, 2, 2, 2, 2])

Correct

Question 2

What is the result of the following lines of code?

a=np.array([0,1])
b=np.array([1,0])
np.dot(a,b)
  • 0
  • 1
  • array([1,1])

Correct

Question 3

Is the following operation allowed with numpy arrays?

a=np.array([1,2,3,4], [5,6,7,8](/sj50179/IBM-Data-Science-Professional-Certificate/wiki/1,2,3,4], [5,6,7,8))
a*[1,2,3,4]
  • no, the two elements must be of equal size
  • yes, this is an example of broadcasting

Correct

Question 4

What is the value of Z after the following code is run?

X=np.array([1,0],[0,1](/sj50179/IBM-Data-Science-Professional-Certificate/wiki/1,0],[0,1))
Y=np.array([0,1],[1,0](/sj50179/IBM-Data-Science-Professional-Certificate/wiki/0,1],[1,0))
Z=X+Y
  • array([ [1, 1],[1, 1] ])
  • array([ [1, 0],[0, 1] ])
  • array([ [0, 1],[1, 1] ])

Correct, the '+' corresponds to matrix addition

Question 5

What values does the variable out take if the following lines of code are run?

X=np.array([1,0,1],[2,2,2](/sj50179/IBM-Data-Science-Professional-Certificate/wiki/1,0,1],[2,2,2))
out=X[0,1:3]
out
  • array([0, 1])
  • array([2, 2])
  • array([1, 0, 1])

Correct, the first index corresponds to the rows the second index corresponds to the columns

Question 6

What is the value of Z after the following code is run?

X=np.array([1,0],[0,1](/sj50179/IBM-Data-Science-Professional-Certificate/wiki/1,0],[0,1))
Y=np.array([2,2],[2,2](/sj50179/IBM-Data-Science-Professional-Certificate/wiki/2,2],[2,2))
Z=np.dot(X,Y)
  • array([ [2, 2],[2, 2]])
  • array([ [2, 0],[0, 2] ])
  • array([ [3, 2],[2, 3]])

Correct, the dot function corresponds to matrix multiplication