UCSanDiegoX: DSE200x Python for Data Science Week 3

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

If you try to access rows of a 3-by-3 numpy array called "arr" using the command: arr[:2,] How many rows will be returned? 2 3 IndexError: index out of bounds

2

What are the 3 reasons that data scientists working in Python use numpy all the time? -Its speed. -Its functionality. -Many packages rely on numpy. It enables text markup cells.

Its speed. Its functionality. Many packages rely on numpy.

Which layer of the 3 layer matrix of colors corresponds to the color blue when working with images in Numpy? Layer 0 Layer 1 Layer 2

Layer 2

Which of the following are benefits of ndarrays over lists? Select 3. Ndarrays are more space efficient. Ndarrays are more optimized for memory. Ndarrays often have faster computation. Ndarrays have more variable types than lists.

Ndarrays are more space efficient. Ndarrays are more optimized for memory. Ndarrays often have faster computation.

In what 3 ways can you quickly access numpy array elements? Slicing Using an array of indices Boolean indexing Segmenting an array

Slicing Using an array of indices Boolean indexing

What command allows you to sum all of the elements in an Rank 2 ndarray called "a"? a.sum() sum(a) A+a a.add()

a.sum()

How do you create an Rank 1 array with numpy using the numbers 1, 2, 3? -np.ndarray([1,2,3]) -np.array([1,2,3]) -np.array(1,2,3) -np.ndarray(1,2,3) -np.ndarray([[1,2,3],[3,2,1]) -np.array([[1,2,3],[3,2,1])

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

Using markdown cells in Jupyter, how do you format text as bold? **word** *word* ##word## #word#

***word***

You are given the following lines of code: arr = np.array([[1,2,3],[4,5,6],[7,8,9]]) slice = arr[:2,1:3] slice[0,0] What is the result of "slice[0,0]" in your last line of code? 1 2 3 4

2

In an RGB images, which three values specifying a pixel's color correspond to the color white? 255, 255, 255 0, 0, 0 100, 100, 100 255, 0, 255

255, 255, 255

Changing an element of an array slice in numpy will NOT change the original array. True False

False

Code in the Jupyter code cells are restricted to being one line. True False

False

When working with cells in Jupyter, what does "_" refer to? -The output of the last cell executed. correct -A space in the line of code. -A string character.

The output of the last cell executed. correct .

What requirement is needed to add two numeric numpy arrays? They need to have the same or compatible dimensions. They need to be of the same type. They need to be converted to type float first.

They need to have the same or compatible dimensions.

Elements in numpy arrays must be all the same type. -True -False

True

Take a look at the following lines of code: a = np.array([2, 3]) b1 = np.array([1]) b2 = 1 True or False: a+b1 and a+b2 result in the same ndarray. True False

True

ndarrays are mutable. -True -False

True

Look at the following code: b = np.array([1,2,3]) b[1] = 'one' What error prints out after you run these two lines of code? -SyntaxError -NameError -KeyError -ValueError

Value Error

What is the result of the following lines of code? a=np.array(["cat","dog","fish"]) b=np.array(["dog","fish","rabbit"]) print(np.setdiff1d(a,b)) ['cat'] ['rabbit'] ['dog' 'fish'] ['cat' 'dog' 'fish' 'rabbit']

['cat']

Select two valid ways to get the odd values of an array "arr." arr[(arr % 2 != 1)] arr[(arr % 2 != 0)] arr[(arr % 2 == 1)] arr[(arr % 2 == 0)]

arr[(arr % 2 != 0)] arr[(arr % 2 == 1)]

You are given the following lines of code: arr = np.array([[1,2,3],[4,5,6],[7,8,9]]) slice = arr[:2,1:3] slice[0,0] What element in arr is equivalent to slice[0,0]? arr[0,0] arr[0,1] arr[2,2] arr[0,2]

arr[0,1]

arr = np.array([[1,2,3,4],[5,6,7,8],[9,10,11,12]]) Which of the following two commands below produce the same result? -arr[0:1,1:3] -arr[2,1:3] -arr[1,1:3] -arr[:1,1:3]

arr[0:1,1:3] arr[:1,1:3]

How would you change the number 5 to 7 in this matrix? arr = np.array([1,2,3,4,5]) -arr[0,5] = 7 -arr[4] = 7 -arr[5] = 7 -arr[0,4] = 7

arr[4] = 7

What is the correct way to access elements of an array "arr" that are less than 0? arr[<0] arr[arr<0] arr[arr[,]<0]

arr[arr<0]

What is the output of the following broadcasting call? A = np.array([[1],[2]]) B = np.array([[1,2],[3,4]]) A + B array([[2, 3], [5, 6]]) array([[2, 4], [4, 6]]) array([[1, 2], [3, 4],[1,2]]) Value Error

array([[2, 3], [5, 6]])


Ensembles d'études connexes

Chapter 12 Somatic Sensory System

View Set

Chapter 7: Strict Liability and Product Liability: Legal and Social Environment

View Set

Chapter 5 The Circulatory System

View Set

NUR 101 Quiz 9 Unit 13: growth and development

View Set

BSC2085L - Appendicular Skeleton

View Set

115 PrepU Chapter 31: Assessment of Immune Function

View Set

Chapter 8 Managing People and Work, MGMT 3340 Ch. 8

View Set

Chapter 16: Health, Disability, and Life Insurance

View Set

Chapter 13 - Central Nervous System Stimulants and Related Drugs

View Set

(3) HIS: Philippine Health Policies and Initiatives

View Set