0% found this document useful (0 votes)
2 views4 pages

Numpy Questions

The document is a practice assignment focused on NumPy arrays, featuring matching exercises, fill-in-the-blank questions, and various operations related to indexing, modification, aggregation, and transformation of arrays. It includes multiple sets of questions that test knowledge on functions, array manipulation, and concepts such as broadcasting and memory sharing. The assignment is structured to enhance understanding and application of NumPy functionalities.

Uploaded by

S H
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

Numpy Questions

The document is a practice assignment focused on NumPy arrays, featuring matching exercises, fill-in-the-blank questions, and various operations related to indexing, modification, aggregation, and transformation of arrays. It includes multiple sets of questions that test knowledge on functions, array manipulation, and concepts such as broadcasting and memory sharing. The assignment is structured to enhance understanding and application of NumPy functionalities.

Uploaded by

S H
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

NumPy Arrays -- Practice Assignment

A. Match the Following

Column A Column B

1. [i * 2 for i in L] Answer: ______ A. Reinterprets an array's layout into new


dimensions, without copying the underlying values
when possible
3. [Link](3) / [Link]((2,2)) Answer: ______ C. A fixed count of evenly spaced values,
guaranteed to include both endpoints
4. [Link](0, 10, 2) Answer: ______ D. The idiomatic NumPy way to index a multi-
dimensional array in one step, supporting mixed slice
+ integer per axis
5. [Link](0, 1, 5) Answer: ______ E. A pre-sized array filled entirely with one constant
value
6. [Link](3) Answer: ______ F. One returns a view that shares memory; the other
always returns an independent copy
7. [Link](1, 7, size=10) Answer: ______ G. Randomly generated values from a seeded,
reproducible generator
8. [Link](3, 4) Answer: ______ H. The loop runs inside NumPy's C implementation
-- no Python-level loop at all
9. [Link]() vs [Link]() Answer: ______ I. Inserts a new length-1 axis, often to make two
arrays broadcast-compatible
10. row[:, [Link]] Answer: ______ J. Evenly spaced values generated using a fixed
step size
12. grid[i, j] Answer: ______ L. An identity-style matrix with 1s on the diagonal

Page 1
Set 2 -- Indexing, Modification & Removal
Column A Column B

1. nums[100:200] Answer: ______ A. Broadcasts a single scalar into every position of a slice

2. data[[0, 2, 4]] Answer: ______ B. Returns a new array with a value inserted at a specific index

3. temps[temps > 70] Answer: ______ C. Boolean-mask filtering -- removes elements that match a condition

4. arr[1:4] = [20, 30, 40] Answer: ______ D. Fancy indexing -- always returns a copy, and the index list can
repeat or reorder positions

5. arr[1:4] = 9 Answer: ______ E. Returns the distinct values in an array, with duplicates removed

6. [Link](arr, [4, 5]) Answer: ______ F. Always returns a brand-new, larger array; the original is left
unchanged

7. [Link](arr, 2, 3) Answer: ______ G. Returns an empty array rather than raising an error, because out-
of-range slices clip silently

8. [Link](arr, 7) Answer: ______ H. Changes an array's size by padding or repeating its existing values

9. arr += 10 Answer: ______ I. Slice assignment -- replaces the sliced elements one-for-one

10. [Link](arr, 2) Answer: ______ J. An in-place operation; must keep the array's original dtype

11. [Link](arr) Answer: ______ K. Boolean mask indexing -- keeps only the elements where the
condition is True

12. arr[arr != value] Answer: ______ L. Returns a new array with the value at a given index removed
(NumPy arrays have no .remove())

Page 2
Set 3 -- Aggregation, Combining, Transformation, Copying & Pitfalls

Column A Column B

1. [Link](lookups, arr) Answer: A. A completely independent array with its own separate
______ memory

2. [Link](dice_rolls) Answer: B. Returns the index positions where a condition is True


______

3. [Link](temps > 70) Answer: C. Returns a view of the transposed array -- mutating it
______ mutates the original too

4. [Link](axis=0) Answer: D. Checks membership for many values against an array


______ all at once, elementwise

5. [Link]([a, b]) Answer: E. Joins arrays along a brand-new axis that didn't exist
______ before

6. [Link]([a, b]) Answer: G. Aggregates values by collapsing one specific axis,


______ controlled by the axis parameter

7. A @ B Answer: H. A new array object that shares the same underlying


______ memory as the original

8. grid.T Answer: I. Builds a full frequency table for non-negative integer data
______

9. [Link]() Answer: J. True matrix multiplication -- not the same as elementwise


______ *

10. [Link]() Answer: L. Joins arrays end-to-end along an existing axis


______

Page 3
B. Fill in the Blanks

1. arr ______ 2 # multiplies every element, no explicit loop written by you

2. OneD[OneD ______ 200] # filters down to only the values greater than 200

3. OneD.______() # index position of the largest value, not the value itself

4. [Link](0, 1, 5) guarantees the exact ______ and the exact count of points

5. letters[-1] # retrieves the ______ element of the array

6. nums[3:2] # returns an ______ array rather than raising an error.

Page 4

You might also like