What is the main difference in the output of functions created with `numpy.frompyfunc` versus `numpy.vectorize`?

Correct answer: `frompyfunc` always returns arrays of Python objects, while `vectorize` allows you to specify the output data type.

Explanation

This question differentiates between two ways of creating custom ufuncs in Python, focusing on the practical difference in their output which affects usability and performance.

Other questions

Question 1

What are the four internal components of a NumPy ndarray object?

Question 2

For a typical C order 3 x 4 x 5 array of float64 (8-byte) values, what are the strides?

Question 3

Which 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?

Question 4

What is the primary difference between the NumPy `ravel` and `flatten` array methods?

Question 5

What is the result of reshaping the array `arr = np.arange(12).reshape((3, 4))` using `arr.ravel('F')`?

Question 6

Which pair of NumPy functions are convenience functions for concatenating arrays by rows (axis 0) and by columns (axis 1) respectively?

Question 7

According to the Broadcasting Rule in NumPy, when are two arrays compatible for broadcasting?

Question 8

To 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?

Question 9

What is the purpose of the `np.newaxis` attribute in NumPy?

Question 10

What does the `np.add.reduce` method do on a 1D array?

Question 11

Given the array `arr = np.arange(10)`, what is the output of `np.add.reduceat(arr, [0, 5, 8])`?

Question 12

What is the primary function of the `outer` ufunc method, for example, `np.multiply.outer(x, y)`?

Question 13

How is a typical structured data type specified when creating a NumPy structured array?

Question 14

When you access a single field of a structured array, like `sarr['x']`, what is returned?

Question 15

What is a key advantage of using NumPy structured arrays compared to pandas DataFrames for certain applications?

Question 16

What is the fundamental difference between `arr.sort()`, an instance method, and `np.sort(arr)`, a top-level function?

Question 17

Which sorting algorithm in NumPy is the only one guaranteed to be stable?

Question 18

What is the purpose of the `numpy.partition` function?

Question 20

What is the primary purpose of the Numba library in the context of NumPy?

Question 21

In NumPy, what is a memory-mapped file?

Question 22

When you assign data to a slice of a NumPy `memmap` object, when are the changes guaranteed to be written to the on-disk file?

Question 23

What does it mean for a NumPy array's memory layout to be 'C-contiguous'?

Question 24

How can you check the memory layout flags, such as `C_CONTIGUOUS` and `F_CONTIGUOUS`, for a NumPy array named `arr`?

Question 25

If `arr_f` is a FORTRAN-contiguous array, what will be the boolean value of `arr_f.copy('C').flags.C_CONTIGUOUS`?

Question 26

What is the purpose of the strides tuple in a NumPy ndarray's internal structure?

Question 27

When using the `reshape` method on a NumPy array, what does passing -1 as one of the dimension values signify?

Question 28

Given `arr = np.arange(15)`, what is the shape of the resulting array after executing `arr.reshape((5, -1))`?

Question 29

In 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?

Question 30

Which ufunc method produces an array of intermediate 'accumulated' values, similar to how `cumsum` is related to `sum`?

Question 31

Given a 2D array `arr = np.arange(15).reshape((3, 5))`, what is the result of `np.add.accumulate(arr, axis=1)`?

Question 32

What is the primary purpose of `numpy.lexsort`?

Question 33

When using `numpy.lexsort((first_name, last_name))`, which array is used as the primary sort key?

Question 34

Given `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'))`?

Question 35

Which two Python projects are mentioned as providing NumPy-friendly interfaces for storing array data in the HDF5 format?

Question 36

Which of the following is NOT a performance tip mentioned for getting the best performance out of NumPy?

Question 37

What is the method resolution order (MRO) for the `np.float64` data type shown in the text?

Question 38

Which special objects in the NumPy namespace provide a concise way to stack arrays, for example, vertically like `vstack`?

Question 39

How does the `repeat` method work on a multidimensional array if you pass an array of integers instead of a single integer?

Question 40

What is the key difference between `tile` and `repeat` in NumPy?

Question 41

What is the output of `np.tile(arr, (2, 1))` where `arr` is a 2x2 array?

Question 42

What are the NumPy equivalents of fancy indexing `arr[inds]` for getting and setting values on a single axis?

Question 43

What does `numpy.searchsorted` return when searching for a value in a sorted array?

Question 44

Given `arr = np.array([0, 1, 7, 12, 15])`, what is the output of `arr.searchsorted([0, 8, 11, 16])`?

Question 45

In the context of Numba, what is the purpose of the `nopython=True` option in the `jit` function?

Question 46

When opening an existing memory map file with `np.memmap`, what information must you still specify?

Question 47

If an array is C-contiguous, what is generally the fastest way to perform an operation like summing its elements?

Question 48

When you create a view on a C-contiguous array using a slice like `arr_c[:, :50]`, is the resulting view guaranteed to be contiguous?

Question 49

In 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?

Question 50

If 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?