304 North Cardinal St.
Dorchester Center, MA 02124

# From Python to Numpy Educative Quiz Answers

## Get From Python to Numpy Educative Quiz Answers

If you’re looking to grow your career in machine learning or data science in this day and age, adding a powerful library to your skill set is an important place to start. In that vein, Python has become one of the most widely used tools in the industry for serious data analytics, and NumPy is probably the most widely used data analytics library. With NumPy, you can manipulate data involving multi-dimensional arrays and matrices (think linear algebra).

Join us as we venture into the vast world of NumPy in this comprehensive course. Each lesson dive into the actual implementation of concepts in both pure Python and then NumPy, exploring how NumPy vectorization compares to traditional Python that uses a procedural and object-oriented approach.

Practice and test yourself along the way with in-browser coding challenges, quizzes, and more.

This course is intended for users who are already familiar with intermediate level Python.

Enroll on Educative

#### Quiz 1: Creation in NumPy

Q1. How would you create a null vector of size 10?

• Option 1
``````import numpy as np
np.zeros(10)
``````
• Option 2
``````import numpy as np
np.ones(10)``````

Q2. How would you create a null vector of size 10 but the fifth value which is 1?

• Option 1
``````import numpy as np
Z=np.zeros(10)
Z=1
``````
• Option 2
``````import numpy as np
Z=np.zeros(10)
Z=1
``````

Q3. How would you create a 3×3 matrix with values ranging from 0 to 8?

• Option 1
``````import numpy as np
Z = np.arange(9).reshape(3,3)
``````
• Option 2
``````import numpy as np
Z = np.arange(8).reshape(3,3)
``````

#### Quiz 2: Reshaping in NumPy

Q1. Given an array `Z`.How would you reshape an array in 3 rows and 4 columns?

``Z = np.array([0,0,0,0,0,0,0,0,0,0,1,0])``
• Option 1
``Z = np.array([0,0,0,0,0,0,0,0,0,0,1,0]).reshape(4,3)``
• Option 2
``Z = np.array([0,0,0,0,0,0,0,0,0,0,1,0]).reshape(2,2)``
• Option 3
``````Z = np.array([0,0,0,0,0,0,0,0,0,0,1,0]).reshape(3,4)
``````
• Option 4
``Z = np.array([0,0,0,0,0,0,0,0,0,0,1,0]).reshape(4,5)``

#### Quiz 3: Indexing in NumPy

Q1. Given an np array `Z` .How would you get the following values from Z?

``   ┏━━━┓───┬───┐   ┃ 1 ┃ 1 │ 2 │   ┗━━━┛───┏━━━┓   ┏━━━┳━━━┓Z  │ 3 │ 4 ┃ 9 ┃ → ┃ 1 ┃ 9 ┃   ├───┼───┗━━━┛   ┗━━━┻━━━┛   │ 6 │ 7 │ 8 │    (copy)   └───┴───┴───┘``
• Option 1
``````print(Z[[0,1],[0,2]])
``````
• Option 2
``print(Z[[0,0],[1,2]])``
• Option 3
``````print(Z[[0,0],[2,2]])
``````
• Option 4
``````print(Z[[1,1],[2,2]])
``````

#### Quiz 4: Broadcasting in NumPy

Q1. Which of the following operation is not possible in broadcasting?

Assume N is the total size of the NumPy array

• If one operand is N * N and other is N * N
• If one operand is N * 2 and other is N * 3
• If one operand is N * N and other is 1 * N

#### Quiz 5: NumPy Vectorization

Q1. What’s a good alternative in Numpy for the “accumulate” method from Itertools?

• `Numpy.sum()`
• `Numpy.cumsum()`
• `Numpy.add()`
• None of the above

Q2. Out of these three approaches that we discussed, which one was the fastest?

• Procedural approach
• Object-Oriented approach
• Vectorized approach

#### Quiz 6: Readability vs. Speed

Q1. The code written in Numpy module is vectorized. Is this statement True or False?

• True
• False

Q2. The vectorized code is more speed efficient. Is this statement True of False?

• True
• False

#### Quiz 7: Introduction

Q1. How can you increase the speed factor for clearing data from an array(setting all values in an array to 0)?

``Z = np.ones(4*1000000, np.float32)``
• Option 1
``````timeit("Z.view(np.float64)[...] = 0", globals())
``````
• Option 2
``````timeit("Z.view(np.float16)[...] = 0", globals())
``````

#### Quiz 8: Memory layout

Q1. What is the output of the following code?

``Z = np.arange(9).reshape(3,3).astype(np.int32)print(Z.itemsize)``
• 2
• 4

Q2. What is the output of the following code?

``Z=np.arange(9).reshape(3,3).astype(np.int32)stride= Z.shape*Z.itemsize, Z.itemsize print(stride)``
• [6,2]
• [12,4]

#### Quiz 9: Views and Copies

Q1. Does the following code return a view or a copy?

``Z = np.zeros(9)Z_1 = Z[:4] Z_1[...] = 1 ``
• View
• Copy

Q2. What are the two methods to make a view?

• indexing
ravel
• fancy indexing
flatten

Q3. What are the two methods to make a copy?

• indexing
ravel
• fancy indexing
flatten

Q4. Ravel returns a 1-D array, containing the elements of the input. A copy is made only if needed.

• True
• False

Q5. Flatten always returns a copy of the input array, flattened to one dimension.

• True
• False

#### Coding Example: How to find if one vector is view of the other?

``````def calculate_offsets(Z1, Z2):
offset_start = np.byte_bounds(Z2) - np.byte_bounds(Z1)
offset_stop = np.byte_bounds(Z2)[-1] - np.byte_bounds(Z1)[-1]
return [offset_start, offset_stop]``````

#### Quiz 10: Introduction

Q1. Which of the following is a good approach when designing a solution to a problem?

• Think of a brute force Python solution
• Think of vectorization using NumPy tricks

#### Quiz 11: Coding Example: Game of life (NumPy approach)

Q1. What is the purpose of `numpy.argwhere(a)`?

• Find the indices of array elements that are non-zero, grouped by element.
• Find the indices of array elements that are zero, grouped by element.

Q2. What numpy operation is similar to `numpy.argwhere(a)`?

• np.transpose(np.nonzero(a))
• np.transpose(np.ones(a))

#### Quiz 12: Coding Example: The Mandelbrot Set (NumPy approach)

Q1. What does `numpy.less()` do?

• Return the truth value of (x1 < x2) element-wise.
• Return the truth value of (x1 > x2) element-wise.

#### Quiz 13: Coding Example: Implement the behavior of Boids (NumPy approach)

Q1. What is the purpose of `numpy.dstack`?

• Stack arrays in sequence breadth wise (along third axis).
• Stack arrays in sequence depth wise (along third axis).

Q2. What is the output of the following code?

``a = (10,4)b = (3,3)print(np.subtract.outer(a,b))``
• [[7 7] [1 1]]
• [7,1]

#### Quiz 14: Conclusion

Q1. Which type of vectorization approach is this? Elements share the same computation but on dynamic spatial arguments.

• Spatial
• Temporal
• Uniform

Q2. Which type of vectorization approach is this? Elements share the same computation but necessitate a different number of iterations.

• Spatial
• Temporal
• Uniform

Q3. Which type of vectorization approach is this? Elements share the same computation unconditionally and for the same duration

• Spatial
• Temporal
• Uniform

#### Quiz 15: Typed list

Q1. Why makes `Typed List` better than a list while using NumPy?

• All items in a `Typed List` have the same data type unlike list
• `Typed List` takes less computation time unlike list

#### Quiz 16: NumPy & co

Q1. Which of the following supplies routines for faster evaluation of array expressions?

• numexp
• cython
• numba
• theano
• pyopencl
• pycuda

Q2. Which of the following is an optimizing static compiler?

• numexp
• cython
• numba
• theano
• pyopencl
• pycuda

Q3. Which of the following helps you speed up your applications?

• numexp
• cython
• numba
• theano
• pyopencl
• pycuda

Q4. Which of the following allows you to define, optimize, and evaluate mathematical expressions involving multi-dimensional arrays efficiently?

• numexpr
• cython
• numba
• theano
• pyopencl
• pycuda

Q5. Which of the following python library lets you access GPU and other parallel computing devices?

• numexpr
• cython
• numba
• theano
• pyopencl
• pycuda

#### Quiz 17: Scipy & co

Q1. Which of the following python library has built in machine learning algorithm ?

• scikit learn
• sympy
• scikit image

Q2. Which of the following python library is used for symbolic mathematics?

• scikit-learn
• sympy
• scikit image
##### Conclusion:

I hope this From Python to Numpy Educative Quiz Answers would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.

Keep Learning!

More Coding Solutions >>

LeetCode Solutions

Hacker Rank Solutions

CodeChef Solutions