NumPy Basics: Arrays and Vectorized Computation
50 questions available
Questions
What is the primary function of the NumPy ndarray object as described in the chapter?
View answer and explanationWhat does the `dtype` attribute of a NumPy ndarray represent?
View answer and explanationConsider the following code: `import numpy as np; arr = np.array([[1, 2, 3, 4], [5, 6, 7, 8]])`. What will be the output of `arr.ndim`?
View answer and explanationHow does slicing a NumPy array differ from slicing a standard Python list regarding data copying?
View answer and explanationGiven the code: `import numpy as np; arr = np.arange(10); arr_slice = arr[5:8]; arr_slice[1] = 12345`. What is the value of `arr[6]`?
View answer and explanationWhich operator should be used to perform a logical AND operation when combining multiple Boolean conditions on NumPy arrays?
View answer and explanationWhat is the purpose of the `seed` argument when creating a random number generator with `np.random.default_rng(seed=12345)`?
View answer and explanationWhat is a universal function (or ufunc) in NumPy?
View answer and explanationWhat does the `numpy.modf` ufunc return when applied to a floating-point array?
View answer and explanationWhat is the primary function of `numpy.where`?
View answer and explanationWhen using a statistical method like `arr.mean(axis=1)` on a 2D NumPy array, what is being computed?
View answer and explanationWhat is the key difference between the `arr.sort()` method and the `numpy.sort(arr)` function?
View answer and explanationWhich pair of NumPy functions is used for saving and loading a single array in NumPy's uncompressed raw binary format?
View answer and explanationFor two 2D NumPy arrays, `mat1` and `mat2`, which expression correctly performs matrix multiplication?
View answer and explanationIn the context of the random walk simulation, what does calling `.argmax()` on a Boolean array like `(np.abs(walk) >= 10).argmax()` compute?
View answer and explanationWhat is the result of casting a float array to an integer dtype using `astype(np.int32)`?
View answer and explanationWhat is the primary characteristic of 'fancy indexing' in NumPy?
View answer and explanationIf `arr` is a NumPy array, what is the effect of the `.T` attribute?
View answer and explanationWhen comparing the performance of NumPy array operations to pure Python operations on lists for large sequences, what is the typical observation?
View answer and explanationWhat is the output of the following code? `import numpy as np; arr = np.array([3.7, -1.2, -2.6, 0.5, 12.9, 10.1]); print(arr.astype(np.int32))`
View answer and explanationIn a 2D NumPy array `arr2d`, what does the indexing expression `arr2d[0, 2]` select?
View answer and explanationWhat is the result of selecting data from an array using Boolean indexing, such as `data[names == 'Bob']`, in terms of data copying?
View answer and explanationWhat is the function of `numpy.unique` on a 1D ndarray?
View answer and explanationWhat happens when you pass multiple index arrays to a NumPy array, like `arr[[1, 5, 7, 2], [0, 3, 1, 2]]`?
View answer and explanationWhich `numpy.linalg` function is used to compute the inverse of a square matrix?
View answer and explanationWhat does the `any()` method check for in a Boolean array?
View answer and explanationWhat is 'vectorization' as the term is used in the context of NumPy arrays?
View answer and explanationGiven `arr = np.arange(32).reshape((8, 4))`, what is the result of `arr[[1, 5, 7, 2]][:, [0, 3, 1, 2]]`?
View answer and explanationWhat does the `swapaxes` method, for example `arr.swapaxes(0, 1)`, do on an ndarray?
View answer and explanationHow can you create a 3x6 NumPy array filled with zeros?
View answer and explanationWhat is the primary risk of using the `numpy.empty` function to create an array?
View answer and explanationWhat does the NumPy function `np.arange(15)` produce?
View answer and explanationWhat is the result of the expression `arr.cumsum(axis=1)` on a 2D array `arr = np.array([[0, 1, 2], [3, 4, 5], [6, 7, 8]])`?
View answer and explanationIf `numeric_strings = np.array(['1.25', '-9.6', '42'], dtype=np.string_)`, which method converts this array to a numeric floating-point form?
View answer and explanationAccording to the chapter, why is it advisable to use `import numpy as np` instead of `from numpy import *`?
View answer and explanationIn a comparison between arrays of the same size, such as `arr2 > arr`, what is the resulting object?
View answer and explanationWhen simulating many random walks at once, if `nwalks = 5000` and `nsteps = 1000`, what is the shape of the `walks` array created by `steps.cumsum(axis=1)`?
View answer and explanationWhat is the purpose of the `out` argument in some ufuncs, such as `np.add(arr, 1, out=out_array)`?
View answer and explanationWhat would `np.in1d(values, [2, 3, 6])` return if `values` is `np.array([6, 0, 0, 3, 2, 5, 6])`?
View answer and explanationWhen saving multiple arrays to a single file archive, which function should be used?
View answer and explanationIf `arr = np.array([[1., 2., 3.], [4., 5., 6.]])`, what is the result of `1 / arr`?
View answer and explanationIn the `numpy.random` module, how does `shuffle` differ from `permutation`?
View answer and explanationWhat is the function `np.meshgrid` typically used for, as shown in the example in Section 4.4?
View answer and explanationIf `arr` is a NumPy array, what is the key difference between using fancy indexing (`arr[[4, 3, 0]]`) and slicing (`arr[0:4]`) regarding data copying?
View answer and explanationWhat does the `logical_not` ufunc compute?
View answer and explanationConsider the code `arr = np.array([False, False, True, False])`. What will `arr.all()` and `arr.any()` return, respectively?
View answer and explanationWhen sorting a multidimensional array in-place along an axis, for example `arr.sort(axis=0)`, what is the behavior?
View answer and explanationWhat is the key advantage of NumPy's array-oriented computing approach, exemplified by its C-based algorithms?
View answer and explanationIf `arr` is a 5x4 array, what is the shape of the result of `arr.mean(axis=0)`?
View answer and explanationWhat is the purpose of the `svd` function in the `numpy.linalg` module?
View answer and explanation