Advanced NumPy
50 questions available
Questions
What are the four internal components of a NumPy ndarray object?
View answer and explanationFor a typical C order 3 x 4 x 5 array of float64 (8-byte) values, what are the strides?
View answer and explanationWhich NumPy function is used to check if an array's data type is a subclass of a general type like np.integer or np.floating?
View answer and explanationWhat is the primary difference between the NumPy `ravel` and `flatten` array methods?
View answer and explanationWhat is the result of reshaping the array `arr = np.arange(12).reshape((3, 4))` using `arr.ravel('F')`?
View answer and explanationWhich pair of NumPy functions are convenience functions for concatenating arrays by rows (axis 0) and by columns (axis 1) respectively?
View answer and explanationAccording to the Broadcasting Rule in NumPy, when are two arrays compatible for broadcasting?
View answer and explanationTo subtract the row means from a 4x3 array named `arr`, the 1D array of row means, `row_means`, must be reshaped. What is the correct shape for `row_means` to enable broadcasting over axis 1?
View answer and explanationWhat is the purpose of the `np.newaxis` attribute in NumPy?
View answer and explanationWhat does the `np.add.reduce` method do on a 1D array?
View answer and explanationGiven the array `arr = np.arange(10)`, what is the output of `np.add.reduceat(arr, [0, 5, 8])`?
View answer and explanationWhat is the primary function of the `outer` ufunc method, for example, `np.multiply.outer(x, y)`?
View answer and explanationHow is a typical structured data type specified when creating a NumPy structured array?
View answer and explanationWhen you access a single field of a structured array, like `sarr['x']`, what is returned?
View answer and explanationWhat is a key advantage of using NumPy structured arrays compared to pandas DataFrames for certain applications?
View answer and explanationWhat is the fundamental difference between `arr.sort()`, an instance method, and `np.sort(arr)`, a top-level function?
View answer and explanationWhich sorting algorithm in NumPy is the only one guaranteed to be stable?
View answer and explanationWhat is the purpose of the `numpy.partition` function?
View answer and explanationWhat is the main difference in the output of functions created with `numpy.frompyfunc` versus `numpy.vectorize`?
View answer and explanationWhat is the primary purpose of the Numba library in the context of NumPy?
View answer and explanationIn NumPy, what is a memory-mapped file?
View answer and explanationWhen you assign data to a slice of a NumPy `memmap` object, when are the changes guaranteed to be written to the on-disk file?
View answer and explanationWhat does it mean for a NumPy array's memory layout to be 'C-contiguous'?
View answer and explanationHow can you check the memory layout flags, such as `C_CONTIGUOUS` and `F_CONTIGUOUS`, for a NumPy array named `arr`?
View answer and explanationIf `arr_f` is a FORTRAN-contiguous array, what will be the boolean value of `arr_f.copy('C').flags.C_CONTIGUOUS`?
View answer and explanationWhat is the purpose of the strides tuple in a NumPy ndarray's internal structure?
View answer and explanationWhen using the `reshape` method on a NumPy array, what does passing -1 as one of the dimension values signify?
View answer and explanationGiven `arr = np.arange(15)`, what is the shape of the resulting array after executing `arr.reshape((5, -1))`?
View answer and explanationIn the context of NumPy's advanced array manipulation, what is the key difference in how C/row-major order and FORTRAN/column-major order traverse dimensions?
View answer and explanationWhich ufunc method produces an array of intermediate 'accumulated' values, similar to how `cumsum` is related to `sum`?
View answer and explanationGiven a 2D array `arr = np.arange(15).reshape((3, 5))`, what is the result of `np.add.accumulate(arr, axis=1)`?
View answer and explanationWhat is the primary purpose of `numpy.lexsort`?
View answer and explanationWhen using `numpy.lexsort((first_name, last_name))`, which array is used as the primary sort key?
View answer and explanationGiven `values = np.array(['2:first', '2:second', '1:first', '1:second', '1:third'])` and `key = np.array([2, 2, 1, 1, 1])`, what is the output of `values.take(key.argsort(kind='mergesort'))`?
View answer and explanationWhich two Python projects are mentioned as providing NumPy-friendly interfaces for storing array data in the HDF5 format?
View answer and explanationWhich of the following is NOT a performance tip mentioned for getting the best performance out of NumPy?
View answer and explanationWhat is the method resolution order (MRO) for the `np.float64` data type shown in the text?
View answer and explanationWhich special objects in the NumPy namespace provide a concise way to stack arrays, for example, vertically like `vstack`?
View answer and explanationHow does the `repeat` method work on a multidimensional array if you pass an array of integers instead of a single integer?
View answer and explanationWhat is the key difference between `tile` and `repeat` in NumPy?
View answer and explanationWhat is the output of `np.tile(arr, (2, 1))` where `arr` is a 2x2 array?
View answer and explanationWhat are the NumPy equivalents of fancy indexing `arr[inds]` for getting and setting values on a single axis?
View answer and explanationWhat does `numpy.searchsorted` return when searching for a value in a sorted array?
View answer and explanationGiven `arr = np.array([0, 1, 7, 12, 15])`, what is the output of `arr.searchsorted([0, 8, 11, 16])`?
View answer and explanationIn the context of Numba, what is the purpose of the `nopython=True` option in the `jit` function?
View answer and explanationWhen opening an existing memory map file with `np.memmap`, what information must you still specify?
View answer and explanationIf an array is C-contiguous, what is generally the fastest way to perform an operation like summing its elements?
View answer and explanationWhen you create a view on a C-contiguous array using a slice like `arr_c[:, :50]`, is the resulting view guaranteed to be contiguous?
View answer and explanationIn a NumPy structured array, if a field is defined with a shape, such as `('x', np.int64, 3)`, what does accessing that field on a single record, like `arr[0]['x']`, return?
View answer and explanationIf you have a 3D array `arr` with shape (3, 4, 5) and a 2D array `means` with shape (3, 4) representing the means over axis 2, how must you reshape `means` to subtract it from `arr` using broadcasting?
View answer and explanation