Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. What is the result of the following code? import numpy as np x = np.array([1,

ID: 3891417 • Letter: 1

Question

1. What is the result of the following code?
import numpy as np
x = np.array([1,4,5])
y = x
print(x + y) (Points : 1)        [1,4,5,1,4,5]
       [2,5,10]
       [2,8,10]
       [2,10,10] Question 2.2. Which Numpy function do you use to create an array? (Points : 1)        np
       np.array
       np.numpy
       numpy Question 3.3. What is the resulting Numpy array z after executing the following lines of code?
import numpy as np
x = np.array([1, 2, 3])
y = np.array([3, 2, 1])
z = x + y (Points : 1)        array([4, 4, 4])
       array([1, 2, 3, 3, 2, 1])
       array([2, 4, 6])
       array([13, 22, 31]) Question 4.4. Which Python command do you use to select the string "g" from x shown below?
import numpy as np
x = np.array([["a", "b", "c", "d"], ["e", "f", "g", "h"]])
(Points : 1)        x[-1,1]
       x[0][1]
       x[1,2]
       x[0,2] Question 5.5. What is the result of z in the following code?
import numpy as np
x = np.array([[1, 2, 3], [1, 2, 3]])
y = np.array([[1, 1, 1], [1, 2, 3]])
z = x - y (Points : 1)        array([[1, 2, 3],
[1, 2, 3],
[1, 1, 1],
[1, 2, 3]])

       array([[0, 1, 2], [0, 0, 0]])
       array([[0, 0, 0], [0, 1, 2]])
       A 2-by-3 Numpy array with only zeros. Question 6.6. Consider the following code. We want to find the mean of x based on its second column. Which one is the correct response?

import numpy as np
x = np.array([[28, 18],
[34, 14],
[32, 16],
...
[26, 23],
[23, 17]])
(Points : 1)        np.mean(x[1,:])

       np.mean(x[:,1])

       np.mean(x[0,:])

       np.mean(x[:,0])
Question 7.7. Consider the following code.

x=np.ones((3,4))
y = x.reshape(?)

Instead of ?, which one is acceptable? (Points : 1)        (6,2)
       (3,5)
       (5,2)
       (2,4) Question 8.8. What is the result of the following code?
import numpy as np
x = np.array([1,2,3],[4,5,6],[7,8,9])
y =0
for value in x.flat:
y+=value
print(y) (Points : 1)        40
       45
       50
       55 Question 9.9. What is the result of the following code?

a = np.array([1,2,3,4])
a.sum()
(Points : 1)        7
       8
       9
       10 Question 10.10. What is the result of the following code?
a = np.array([1,2,3,4,5,6]).reshape(3,2)
a[2,1]
(Points : 1)        3
       4
       5
       6 Question 11.11. Which keyword in Pandas used to create a dataframe in pandas?
(Points : 1)        pd.table
       pd.Frame
       pd.DataFrame
       pd.Series Question 12.12. What is the output of the following code?
a = pd.Series([10,9,0,1])
a[1]
(Points : 1)        0
       1
       9
       10 Question 13.13. What is the output of the following code?
a= pd.Series([1,2,3,4], index =list('ABCD'))
a['C'] (Points : 1)        1
       2
       3
       4 Question 14.14. What is the output of the following code?
a= pd.Series([1,2,3,4], index =list('ABCD'))
a[['B','C']]
(Points : 1)        
B 2
C 3
       
B 1
C 3
       
A 2
C 3
       
B 2
C 0 Question 15.15. What is the output of the following code?

a = pd.Series([1],index=['A'])
b = pd.Series([1,2,3],index=list('ABC'))
a.add(b,fill_value = 0) (Points : 1)        
A 2.0
B 2.0
C 3.0
       
A 2.0
B NaN
C NaN
       
A 2.0
B NaN
C 3.0

       
A 2.0
B 4.0
C 6.0
Question 16.16. What is the output of the following code?
df = pd.DataFrame(np.arange(9).reshape((3,3)), columns = list('ABC'))

df.ilo[1] (Points : 1)        
A 3
B 4
C 5
       
A 1
B 2
C 3
       
0 3
1 4
2 5
       
0 1
1 2
2 3
Question 17.17. What is the output of the following code?
df = pd.DataFrame(np.arange(9).reshape((3,3)), columns = list('ABC'))
df.ix[0,'A']
(Points : 1)        0
       1
       2
       3 Question 18.18. What is the output of the following code?

df = pd.DataFrame(np.arange(9).reshape((3,3)), columns = list('ABC'))
df.sum(axis =1)
(Points : 1)        
A 9
B 12
C 15
       
A 9
B 15
C 23
       
0 9
1 12
2 15

       
0 9
1 15
2 23
Question 19.19. Consider the following dataframe df in pandas.
A B C
0 0.0 1 2
1 NaN 4 5
2 6.0 7 8

what is the result of the following code?
df.dropna() (Points : 1)        
A B C
0 0.0 1 2
2 6.0 7 8

       
B C
0 1 2
1 4 5
2 7 8

       
B C
0 1 2
2 7 8

       
A B C
0 0.0 1 2
1 6.0 7 8
Question 20.20. Consider the following dataframe df in pandas.
A B C
0 0.0 1 2
1 NaN 4 5
2 6.0 7 8

what is the result of the following code?
df.ix[1,'A']=0
df.sum() (Points : 1)        
A 6.0
B 12.0
C 15.0
       
0 6.0
1 12.0
2 15.0
       
A 6.0
B 15.0
C 12.0

       
0 6.0
1 15.0
2 12.0
Question 21.21. Consider the following dataframe df in pandas.
A B C
0 0.0 1 2
1 0.0 4 5
2 6.0 7 8

what is the result of the following code?
del df[['A','B']]
(Points : 1)        
C
0 2
1 5
2 8

       
A B
0 0.0 1
1 0.0 4
2 6.0 7

       
A
0 0.0
1 0.0
2 6.0

       
A B C
0 0.0 1 2
1 0.0 4 5
2 6.0 7 8
Question 22.22. Consider the following dataframe df in pandas.
A B C
0 0.0 1 2
1 0.0 4 5
2 6.0 7 8

what is the result of the following code?
df.drop(0:2)
(Points : 1)        
A B C
0 0.0 1 2
1 0.0 4 5


       
A B C
2 6.0 7 8

       
A B C
1 0.0 4 5
2 6.0 7 8

       
A B C
0 0.0 1 2
1 0.0 4 5
2 6.0 7 8
Question 23.23. Consider the following dataframe df in pandas.
A B
0 0 1
1 0 4
2 6 7

What is the result of the following code?
df['C']= pd.Series([0, 0 ,1]) (Points : 1)        
A B C
0 0 1 0
1 0 4 0



       
A B C
0 0 1 0
1 0 4 0
2 6 7 1

       
A B  
0 0 1  
1 0 4  
2 6 7  
3 0 1
4 1 NaN


       
A B C
1 0 4 0
2 6 7 1
Question 24.24. What is the output of the following code?

var = {'a':1,'b':2}
df = pd.Series(var) (Points : 1)        
0 1
1 2

       
b 1
a 2

       
a 1
b 2

       
1 1
2 2
Question 25.25. Consider the following series S1 in pandas,

a NaN
b NaN
c 2.6
d NaN

How many True will be printed in the following code?
S1.notnull() (Points : 1)        1
       2
       3
       4 1. What is the result of the following code?
import numpy as np
x = np.array([1,4,5])
y = x
print(x + y) (Points : 1)        [1,4,5,1,4,5]
       [2,5,10]
       [2,8,10]
       [2,10,10]

Explanation / Answer

1. [2,8,10]

Element-wise addition is done.

2. np.array is used

3. array( [4, 4, 4] )

Element to element addition is done

4. x[1, 2] is the correct answer.

1 means the second element of the outer array and then 2 grabs the third element of the inner array.

5.

6.    np.mean(x[:,1])

: specifies that all the rows and 1 means the second column

7. Initial array size is 3*4 = 12 which can be changed to 6*2 = 12

8. 45

sum of all the elements of the array

9. 10 => sum of all the elements

10. 6

reshape(m,n) means reshape array with m rows and n columns.

11. pd.DataFrame

12. 9

13. 3

14.

B 2
C 3

15.

A 2.0
B 2.0
C 3.0