Search
Search Results
Search finished, found 245 page(s) matching the search query.
- numpy.require
...NumPy reference Routines and objects by topic Array manipulation routines numpy.require...
- numpy.require (Python function, in numpy.require)
numpy.distutils
user guide...a collection of scientific tools for Python. The aim of this document is to describe how to add new tools to SciPy. Requirements for SciPy packages SciPy consists of Python packages, called SciPy packages, that are available to Python u...
- Array creation
...that read the data, one can wrap that library with a variety of techniques though that certainly is much more work and requires significantly more advanced knowledge to interface with C or C++. 6) Use of special library functions (e.g.,...
- Array iterator API
...like output parameters, preservation of memory layouts, and buffering of data with the wrong alignment or type, without requiring difficult coding. This page documents the API for the iterator. The iterator is named NpyIter and functions ar...
- Building from source
...rying to install NumPy, we recommend using binaries - see Installation for details on that. Building NumPy from source requires setting up system-level dependencies (compilers, BLAS/LAPACK libraries, etc.) first, and then invoking a build....
- Building the NumPy API and reference docs
...WSL is a good option for a persistent local set-up. Prerequisites Building the NumPy documentation and API reference requires the following: NumPy Since large parts of the main documentation are obtained from NumPy via import numpy and...
- Contributing to NumPy
...ail before the PR and pass afterwards. You should run the tests before pushing a PR. Running NumPy’s test suite locally requires some additional packages, such as pytest and hypothesis. The additional testing dependencies are listed in requ...
- CPU build options
...y used to change the default behavior of optimizations that target certain CPU features: cpu-baseline: minimal set of required CPU features.Default value is min which provides the minimum CPU features that can safely run on a wide range o...
- Data types
...ta element in the array must fit inside. This means that storing an array of byte sequences or strings using this dtype requires knowing or calculating the sizes of the longest text or byte sequence in advance. As an example, we can create...
- For downstream package authors
...er well known scientific Python projects, does not use semantic versioning. Instead, backwards incompatible API changes require deprecation warnings for at least two releases. For more details, see NEP 23 — Backwards compatibility and depre...
- How to contribute to the NumPy documentation
...ious wording mistakes (like leaving out a “not”) fall into the typo category, but other rewordings – even for grammar – require a judgment call, which raises the bar. Test the waters by first presenting the fix as an issue. Some functions/o...
- How to extend NumPy
...ype or add a new data type for ndarrays. This chapter documents the API calls and macros that are most commonly used. Required subroutine There is exactly one function that must be defined in your C-code in order for Python to use it as a...
- Legacy random generation
...t would have been produced by previous versions of NumPy. RandomState adds additional information to the state which is required when using Box-Muller normals since these are produced in pairs. It is important to use RandomState.get_state,...
- Memory alignment
...aligned in memory if its memory offset is a multiple of its alignment. On some systems (eg. sparc) memory alignment is required; on others, it gives a speedup. “Uint” alignment depends on the size of a datatype. It is defined to be the “Tr...
- Memory management in NumPy
...Memory management in NumPy The numpy.ndarray is a python class. It requires additional memory allocations to hold numpy.ndarray.strides, numpy.ndarray.shape and numpy.ndarray.data attribu...
- NumPy 1.10.0 Release Notes
...bin the values, which scales much better for larger number of bins than the previous linear search. It also removes the requirement for the input array to be 1-dimensional. np.poly now casts integer inputs to float np.poly will now cast 1...
- NumPy 1.10.1 Release Notes
...t users would not have seen these problems. The differences are: Compiling with msvc9 or msvc10 for 32 bit Windows now requires SSE2. This was the easiest fix for what looked to be some miscompiled code when SSE2 was not used. If you need...
- NumPy 1.11.0 Release Notes
...Build System Changes Numpy now uses setuptools for its builds instead of plain distutils. This fixes usage of install_requires='numpy' in the setup.py files of projects that depend on Numpy (see gh-6551). It potentially affects the way t...
- NumPy 1.11.2 Release Notes
.... #7904 BUG: Fix float16 type not being called due to wrong ordering. #7917 BUG: Production install of numpy should not require nose. #7919 BLD: Fixed MKL detection for recent versions of this library. #7920 BUG: Fix for issue #7835 (ma.med...
- NumPy 1.12.0 Release Notes
...oad specific libraries during numpy initialization. For example, if we are distributing numpy with a BLAS library that requires SSE2 instructions, we would like to check the machine on which numpy is running does have SSE2 in order to give...
- NumPy 1.13.0 Release Notes
...+ b + c is transformed to d = a + b; d += c which can improve performance for large arrays as less memory bandwidth is required to perform the operation. axes argument for unique In an N-dimensional array, the user can now choose the axi...
- NumPy 1.14.0 Release Notes
...fCopy, have been added together with a complementary flag, NPY_ARRAY_WRITEBACKIFCOPY. Using the new functionality also requires that some flags be changed when new arrays are created, to wit: NPY_ARRAY_INOUT_ARRAY should be replaced by NPY...
- NumPy 1.15.0 Release Notes
...his only enables you to compile NumPy for one specific platform at a time. Creating a full iOS-compatible NumPy package requires building for the 5 architectures supported by iOS (i386, x86_64, armv7, armv7s and arm64), and combining these...
- NumPy 1.15.1 Release Notes
...UG: Fix printing of longdouble on ppc64le. #11760: BUG: Fixes for unicode field names in Python 2 #11761: BUG: Increase required cython version on python 3.7 #11763: BUG: check return value of _buffer_format_string #11775: MAINT: Make asser...
- NumPy 1.16.0 Release Notes
...ed assignment changes: assign_fields_by_name structured_to_unstructured unstructured_to_structured apply_along_fields require_fields See the user guide at <https://docs.scipy.org/doc/numpy/user/basics.rec.html> for more info. New de...
- NumPy 1.16.3 Release Notes
....3.4. The most noticeable change in this release is that unpickling object arrays when loading *.npy or *.npz files now requires an explicit opt-in. This backwards incompatible change was made in response to CVE-2019-6446. Compatibility no...
- NumPy 1.17.0 Release Notes
...e array with internal overlap, making it unsafe to write to. A future version will set the writeable flag to False, and require users to manually set it to True if they are sure that is what they want to do. Now writing to it will emit a de...
- NumPy 1.18.0 Release Notes
...n on datetime64 and timedelta64 dtypes. Also added specific loops for numpy.fmin and numpy.fmax that mask NaT. This may require adjustment to user- facing code. Specifically, code that either disallowed the calls to numpy.isinf or numpy.isn...
- NumPy 1.20.0 Release Notes
...r calls such as numpy.add.outer. Previously, matrix was converted to an array here. This will not be done in the future requiring a manual conversion to arrays. (gh-16232) Further Numeric Style types Deprecated The remaining numeric-style...
- NumPy 1.20.1 Release Notes
...py bugs when wrapping F90 subroutines. #18356: MAINT: crackfortran regex simplify #18357: BUG: threads.h existence test requires GLIBC > 2.12. #18359: REL: Prepare for the NumPy 1.20.1 release....
- NumPy 1.20.3 Release Notes
...8924: MAINT, CI: treats _SIMD module build warnings as errors through… #18925: BUG: for MINGW, threads.h existence test requires GLIBC > 2.12 #18941: BUG: Make changelog recognize gh- as a PR number prefix. #18948: REL, DOC: Prepare for the...
- NumPy 1.22.0 Release Notes
...356) Python 3.7 is no longer supported Python support has been dropped. This is rather strict, there are changes that require Python >= 3.8. (gh-19665) str/repr of complex dtypes now include space after punctuation The repr of np.dtype(...
- NumPy 1.22.4 Release Notes
...S #21472: BUG: Ensure compile errors are raised correctly #21473: BUG: Fix segmentation fault #21474: MAINT: Update doc requirements #21475: MAINT: Mark npy_memchr with no_sanitize("alignment") on clang #21512: DOC: Proposal - make the doc...
- NumPy 1.23.0 Release Notes
...y_XDECREF_ERR was also removed. These were all deprecated in 1.14. They are replaced by NPY_ARRAY_WRITEBACKIFCOPY, that requires calling PyArray_ResolveWritebackIfCopy before the array is deallocated. (gh-20589) Exceptions will be raised d...
- NumPy 1.23.5 Release Notes
...22490: MAINT, CI: Switch to cygwin/cygwin-install-action@v2 #22494: TST: Make test_partial_iteration_cleanup robust but require leak… #22592: MAINT: Ensure graceful handling of large header sizes #22593: TYP: Spelling alignment for array fl...
- NumPy 1.24 Release Notes
...or being used by the singleton RandomState. This is provided to simplify restoring the original source of randomness if required. The preferred method to generate reproducible random numbers is to use a modern bit generator in an instance o...
- NumPy 1.26.0 Release Notes
...5.x release cycle with the addition of Python 3.12.0 support. Python 3.12 dropped distutils, consequently supporting it required finding a replacement for the setup.py/distutils based build system NumPy was using. We have chosen to use the...
- NumPy 1.26.3 Release Notes
...repare 1.26.x for further development #25188: TYP: add None to __getitem__ in numpy.array_api #25189: BLD,BUG: quadmath required where available [f2py] #25190: BUG: alpha doesn’t use REAL(10) #25191: BUG: Fix FP overflow error in division w...
- NumPy 1.7.2 Release Notes
...rs when not filled enough gh-3192: f2py crashes with UnboundLocalError exception gh-442: Concatenate with axis=None now requires equal number of array elements gh-2485: Fix for astype(‘S’) string truncate issue gh-3312: bug in count_nonzero...
- NumPy 1.8.0 Release Notes
...mine how much memory to allocate. In previous releases only sizeof(PyArrayObject) bytes of memory were allocated, often requiring C-API subtypes to reimplement tp_new. Deprecations The ‘full’ and ‘economic’ modes of qr factorization are...
- NumPy 1.9.0 Release Notes
...rictions. np.einsum('ijk,j->ijk', A, B) can also be written as np.einsum('ij...,j->ij...', A, B) (ellipsis is no longer required on ‘j’) Indexing The NumPy indexing has seen a complete rewrite in this version. This makes most advanced int...
- NumPy 2.0 migration guide
...("long", copy=False). Libraries interfacing with compiled code that are written in C, Cython, or a similar language may require updating to accommodate user input if they are using the long or equivalent type on the C-side. In this case, yo...
- NumPy 2.0.0 Release Notes
...al memory address. Unlike PyArray_SETITEM this function is equivalent to setting an individual array item and does not require a NumPy array input. (gh-25954) The ->f slot has been removed from PyArray_Descr. If you use this slot, replace...
- NumPy benchmarks
.... Prefer ASV’s time_ methods for benchmarking times rather than cooking up time measurements via time.clock, even if it requires some juggling when writing the benchmark. Preparing arrays etc. should generally be put in the setup method rat...
- NumPy C code explanations
...o that it can be performed in multiple places. Broadcasting is handled by the function PyArray_Broadcast. This function requires a PyArrayMultiIterObject (or something that is a binary equivalent) to be passed in. The PyArrayMultiIterObject...
- NumPy core math library
...point values. While this format is not typically used for numerical computations, it is useful for storing values which require floating point but do not need much precision. It can also be used as an educational tool to understand the natu...
- NumPy for MATLAB users
...a multidimensional array. Array assignments in NumPy are usually stored as n-dimensional arrays with the minimum type required to hold the objects in sequence, unless you specify the number of dimensions and type. NumPy performs operation...
- NumPy project governance and decision-making
...articular the section on Consensus-based Democracy, for a more detailed discussion. In this context, consensus does not require: that we wait to solicit everybody’s opinion on every change, that we ever hold a vote on anything, or that eve...
- NumPy quickstart
..., 7], [ 8, 10, 10, 11]]) Sometimes copy should be called after slicing if the original array is not required anymore. For example, suppose a is a huge intermediate result and the final result b only contains a small frac...
- NumPy security
...kill, which is a possible denial of service attack. Possible causes could be: Functions reading text files, which may require much more memory than the original input file size. If users can create arbitrarily shaped arrays, NumPy’s broad...
- numpy.array
...ly be made if __array__ returns a copy, if obj is a nested sequence, or if a copy is needed to satisfy any of the other requirements (dtype, order, etc.). Note that any copy of the data is shallow, i.e., for arrays with object dtype, the ne...
- numpy.asanyarray
...eded, i.e. if __array__ returns a copy, if obj is a nested sequence, or if a copy is needed to satisfy any of the other requirements (dtype, order, etc.). For False it raises a ValueError if a copy cannot be avoided. Default: None. New in...
- numpy.asarray
...eded, i.e. if __array__ returns a copy, if obj is a nested sequence, or if a copy is needed to satisfy any of the other requirements (dtype, order, etc.). For False it raises a ValueError if a copy cannot be avoided. Default: None. New in...
- numpy.asarray_chkfinite
...ed to an array. This includes lists, lists of tuples, tuples, tuples of tuples, tuples of lists and ndarrays. Success requires no NaNs or Infs. dtypedata-type, optionalBy default, the data-type is inferred from the input data. order{‘C’...
- numpy.ascontiguousarray
...with type dtype if specified. See also asfortranarrayConvert input to an ndarray with column-major memory order. requireReturn an ndarray that satisfies requirements. ndarray.flagsInformation about the memory layout of the array....
- numpy.asfortranarray
...to a contiguous (C order) array. asanyarrayConvert input to an ndarray with either row or column-major memory order. requireReturn an ndarray that satisfies requirements. ndarray.flagsInformation about the memory layout of the array....
- numpy.bartlett
...0.72727273, 0.54545455, 0.36363636, 0.18181818, 0. ]) Plot the window and its frequency response (requires SciPy and matplotlib). import matplotlib.pyplot as plt from numpy.fft import fft, fftshift window = np.bartlett...
- numpy.cbrt
...<ufunc 'cbrt'> Return the cube-root of an array, element-wise. Parameters: xarray_likeThe values whose cube-roots are required. outndarray, None, or tuple of ndarray and None, optionalA location into which the result is stored. If provid...
- numpy.char.array
...ly be made if __array__ returns a copy, if obj is a nested sequence, or if a copy is needed to satisfy any of the other requirements (itemsize, unicode, order, etc.). unicodebool, optionalWhen true, the resulting chararray can contain Unic...
- numpy.char.chararray.astype
...onalBy default, astype always returns a newly allocated array. If this is set to false, and the dtype, order, and subok requirements are satisfied, the input array is returned instead of a copy. Returns: arr_tndarrayUnless copy is False...
- numpy.char.chararray.shape
...is inferred from the size of the array and the remaining dimensions. Reshaping an array in-place will fail if a copy is required. Warning Setting arr.shape is discouraged and may be deprecated in the future. Using ndarray.reshape is the p...
- numpy.cumulative_prod
...omputed. The default (None) is only allowed for one-dimensional arrays. For arrays with more than one dimension axis is required. dtypedtype, optionalType of the returned array, as well as of the accumulator in which the elements are multi...
- numpy.cumulative_sum
...omputed. The default (None) is only allowed for one-dimensional arrays. For arrays with more than one dimension axis is required. dtypedtype, optionalType of the returned array and of the accumulator in which the elements are summed. If d...
- numpy.digitize
...bin the values, which scales much better for larger number of bins than the previous linear search. It also removes the requirement for the input array to be 1-dimensional. For monotonically increasing bins, the following are equivalent: np...
- numpy.distutils.ccompiler_opt
...he command arguments, to managing the relation between the CPU baseline and dispatch-able features, also generating the required C headers and ending with compiling the sources with proper compiler’s flags. CCompilerOpt doesn’t provide runt...
- numpy.distutils.ccompiler_opt.CCompilerOpt.dist_info
...s.ccompiler_opt.CCompilerOpt.dist_info()[source] Return a tuple containing info about (platform, compiler, extra_args), required by the abstract class ‘_CCompiler’ for discovering the platform environment. This is also used as a cache facto...
- numpy.distutils.ccompiler_opt.CCompilerOpt.dist_load_module
...dule method static distutils.ccompiler_opt.CCompilerOpt.dist_load_module(name, path)[source] Load a module from file, required by the abstract class ‘_Cache’....
- numpy.distutils.ccompiler_opt.CCompilerOpt.feature_detect
...e_detect method distutils.ccompiler_opt.CCompilerOpt.feature_detect(names)[source] Return a list of CPU features that required to be detected sorted from the lowest to highest interest....
- numpy.distutils.ccompiler_opt.CCompilerOpt.parse_targets
...thod distutils.ccompiler_opt.CCompilerOpt.parse_targets(source)[source] Fetch and parse configuration statements that required for defining the targeted CPU features, statements should be declared in the top of source in between C comment...
- numpy.distutils.exec_command
...ariable PATH. Equivalent to posix which command. Author: Pearu Peterson <pearu@cens.ioc.ee> Created: 11 January 2003 Requires: Python 2.x Successfully tested on: os.name sys.platform comments posix linux2 Debian (sid) Linux, Python...
- numpy.dtype
...type({'surname':('S25',0),'age':(np.uint8,25)}) dtype([('surname', 'S25'), ('age', 'u1')]) Attributes: alignmentThe required alignment (bytes) of this data-type according to the compiler. baseReturns dtype for the base element of the s...
- numpy.dtype.alignment
...numpy.dtype.alignment attribute dtype.alignment The required alignment (bytes) of this data-type according to the compiler. More information is available in the C-API secti...
- numpy.dtype.descr
...numpy.dtype.descr attribute dtype.descr __array_interface__ description of the data-type. The format is that required by the ‘descr’ key in the __array_interface__ attribute. Warning: This attribute exists specifically for __arra...
- numpy.dtype.flags
...largely useful for user-defined data-types. The following example demonstrates that operations on this particular dtype requires Python C-API. Examples >>> import numpy as np >>> x = np.dtype([('a', np.int32, 8), ('b', np.float64, 6)]) >>>...
- numpy.dtype.hasobject
...ndarray memory representing the Python object is the memory address of that object (a pointer). Special handling may be required, and this attribute is useful for distinguishing data types that may contain arbitrary Python objects and data-...
- numpy.einsum
...edes subscript ‘i’. In explicit mode the output can be directly controlled by specifying output subscript labels. This requires the identifier ‘->’ as well as the list of output subscript labels. This feature increases the flexibility of t...
- numpy.emath.arccos
...herwise, the complex principle value is returned. Parameters: xarray_like or scalarThe value(s) whose arccos is (are) required. Returns: outndarray or scalarThe inverse cosine(s) of the x value(s). If x was a scalar, so is out, otherw...
- numpy.emath.arcsin
...herwise, the complex principle value is returned. Parameters: xarray_like or scalarThe value(s) whose arcsin is (are) required. Returns: outndarray or scalarThe inverse sine(s) of the x value(s). If x was a scalar, so is out, otherwis...
- numpy.emath.arctanh
...plex. Finally, x = 1 returns``inf`` and x=-1 returns -inf. Parameters: xarray_likeThe value(s) whose arctanh is (are) required. Returns: outndarray or scalarThe inverse hyperbolic tangent(s) of the x value(s). If x was a scalar so is...
- numpy.emath.log
...urns inf). Otherwise, the complex principle value is returned. Parameters: xarray_likeThe value(s) whose log is (are) required. Returns: outndarray or scalarThe log of the x value(s). If x was a scalar, so is out, otherwise an array i...
- numpy.emath.log10
...se, the complex principle value is returned. Parameters: xarray_like or scalarThe value(s) whose log base 10 is (are) required. Returns: outndarray or scalarThe log base 10 of the x value(s). If x was a scalar, so is out, otherwise an...
- numpy.emath.log2
...f). Otherwise, the complex principle value is returned. Parameters: xarray_likeThe value(s) whose log base 2 is (are) required. Returns: outndarray or scalarThe log base 2 of the x value(s). If x was a scalar, so is out, otherwise an...
- numpy.emath.logn
...rameters: narray_likeThe integer base(s) in which the log is taken. xarray_likeThe value(s) whose log base n is (are) required. Returns: outndarray or scalarThe log base n of the x value(s). If x was a scalar, so is out, otherwise an...
- numpy.fabs
...nd the absolute values of complex data. Parameters: xarray_likeThe array of numbers for which the absolute values are required. If x is a scalar, the result y will also be a scalar. outndarray, None, or tuple of ndarray and None, optiona...
- numpy.fliplr
...in one or more dimensions. rot90Rotate array counterclockwise. Notes Equivalent to m[:,::-1] or np.flip(m, axis=1). Requires the array to be at least 2-D. Examples >>> import numpy as np >>> A = np.diag([1.,2.,3.]) >>> A array([[1., 0....
- numpy.flipud
...one or more dimensions. rot90Rotate array counterclockwise. Notes Equivalent to m[::-1, ...] or np.flip(m, axis=0). Requires the array to be at least 1-D. Examples >>> import numpy as np >>> A = np.diag([1.0, 2, 3]) >>> A array([[1., 0...
- numpy.histogram_bin_edges
...’s rule. ‘rice’Estimator does not take variability into account, only data size. Commonly overestimates number of bins required. ‘sturges’R’s default method, only accounts for data size. Only optimal for gaussian data and underestimates n...
- numpy.i: a SWIG interface file for NumPy
...one-dimensional input arrays of type double to the actual prototype used by rms. Using numpy.i effectively, therefore, requires knowing what typemaps are available and what they do. A SWIG interface file that includes the SWIG directives g...
- numpy.in1d
...of ar2. assume_unique has no effect when the ‘table’ option is used. If None, will automatically choose ‘table’ if the required memory allocation is less than or equal to 6 times the sum of the sizes of ar1 and ar2, otherwise will use ‘sor...
- numpy.indices
...] array([[0, 1, 2], [4, 5, 6]]) Note that it would be more straightforward in the above example to extract the required elements directly with x[:2, :3]. If sparse is set to true, the grid will be returned in a sparse representatio...
- numpy.isin
...lements. assume_unique has no effect when the ‘table’ option is used. If None, will automatically choose ‘table’ if the required memory allocation is less than or equal to 6 times the sum of the sizes of element and test_elements, otherwise...
- numpy.lib.add_newdoc
...tion to an existing object, typically one defined in C The purpose is to allow easier editing of the docstrings without requiring a re-compile. This exists primarily for internal use within numpy itself. Parameters: placestrThe absolute n...
- numpy.lib.format
...y accurately. The data is intact; only the field names will differ. We are working on a fix for this. This fix will not require a change in the file format. The arrays with such structures can still be saved and restored, and the correct dt...
- numpy.lib.format.open_memmap
...shapetuple of intThe shape of the array if we are creating a new file in “write” mode, in which case this parameter is required. Otherwise, this parameter is ignored and is thus optional. fortran_orderbool, optionalWhether the array shou...
- numpy.lib.format.read_array
...ax_header_sizeint, optionalMaximum allowed size of the header. Large headers may not be safe to load securely and thus require explicitly passing a larger value. See ast.literal_eval for details. This option is ignored when allow_pickle is...
- numpy.lib.format.read_array_header_1_0
...ax_header_sizeint, optionalMaximum allowed size of the header. Large headers may not be safe to load securely and thus require explicitly passing a larger value. See ast.literal_eval for details. Raises: ValueErrorIf the data is invali...
- numpy.lib.format.read_array_header_2_0
...ax_header_sizeint, optionalMaximum allowed size of the header. Large headers may not be safe to load securely and thus require explicitly passing a larger value. See ast.literal_eval for details. Returns: shapetuple of intThe shape of...
- numpy.lib.npyio.DataSource
...If destpath is None, a temporary directory will be created. The default path is the current directory. Notes URLs require a scheme string (http://) to be used, without it they will fail: >>> repos = np.lib.npyio.DataSource() >>> repos...
- numpy.lib.npyio.NpzFile
...ect or a string containing the path to the archive. own_fidbool, optionalWhether NpzFile should close the file handle. Requires that fid is a file-like object. Examples >>> import numpy as np >>> from tempfile import TemporaryFile >>>...
- numpy.lib.scimath.arccos
...herwise, the complex principle value is returned. Parameters: xarray_like or scalarThe value(s) whose arccos is (are) required. Returns: outndarray or scalarThe inverse cosine(s) of the x value(s). If x was a scalar, so is out, otherw...
- numpy.lib.scimath.arcsin
...herwise, the complex principle value is returned. Parameters: xarray_like or scalarThe value(s) whose arcsin is (are) required. Returns: outndarray or scalarThe inverse sine(s) of the x value(s). If x was a scalar, so is out, otherwis...
- numpy.lib.scimath.arctanh
...plex. Finally, x = 1 returns``inf`` and x=-1 returns -inf. Parameters: xarray_likeThe value(s) whose arctanh is (are) required. Returns: outndarray or scalarThe inverse hyperbolic tangent(s) of the x value(s). If x was a scalar so is...
- numpy.lib.scimath.log
...urns inf). Otherwise, the complex principle value is returned. Parameters: xarray_likeThe value(s) whose log is (are) required. Returns: outndarray or scalarThe log of the x value(s). If x was a scalar, so is out, otherwise an array i...
- numpy.lib.scimath.log10
...se, the complex principle value is returned. Parameters: xarray_like or scalarThe value(s) whose log base 10 is (are) required. Returns: outndarray or scalarThe log base 10 of the x value(s). If x was a scalar, so is out, otherwise an...
- numpy.lib.scimath.log2
...f). Otherwise, the complex principle value is returned. Parameters: xarray_likeThe value(s) whose log base 2 is (are) required. Returns: outndarray or scalarThe log base 2 of the x value(s). If x was a scalar, so is out, otherwise an...
- numpy.lib.scimath.logn
...rameters: narray_likeThe integer base(s) in which the log is taken. xarray_likeThe value(s) whose log base n is (are) required. Returns: outndarray or scalarThe log base n of the x value(s). If x was a scalar, so is out, otherwise an...
- numpy.lib.stride_tricks.sliding_window_view
...ow view of the array. The sliding window dimensions are inserted at the end, and the original dimensions are trimmed as required by the size of the sliding window. That is, view.shape = x_shape_trimmed + window_shape, where x_shape_trimmed...
- numpy.load
.... File-like objects must support the seek() and read() methods and must always be opened in binary mode. Pickled files require that the file-like object support the readline() method as well. mmap_mode{None, ‘r+’, ‘r’, ‘w+’, ‘c’}, optiona...
- numpy.ma.array
...), then the returned array may be in any order (either C-, Fortran-contiguous, or even discontiguous), unless a copy is required, in which case it will be C-contiguous. Examples >>> import numpy as np The mask can be initialized with...
- numpy.ma.getmask
...of booleans of the same shape as a, use getmaskarray. Parameters: aarray_likeInput MaskedArray for which the mask is required. See also getdataReturn the data of a masked array as an ndarray. getmaskarrayReturn the mask of a maske...
- numpy.ma.getmaskarray
...ull boolean array of False of the same shape as arr. Parameters: arrarray_likeInput MaskedArray for which the mask is required. See also getmaskReturn the mask of a masked array, or nomask. getdataReturn the data of a masked array...
- numpy.ma.indices
...] array([[0, 1, 2], [4, 5, 6]]) Note that it would be more straightforward in the above example to extract the required elements directly with x[:2, :3]. If sparse is set to true, the grid will be returned in a sparse representatio...
- numpy.ma.make_mask
...y if necessary or requested. The function can accept any sequence that is convertible to integers, or nomask. Does not require that contents must be 0s and 1s, values of 0 are interpreted as False, everything else as True. Parameters: ma...
- numpy.ma.masked_all
...array of the given shape and dtype, where all the data are masked. Parameters: shapeint or tuple of intsShape of the required MaskedArray, e.g., (2, 3) or 2. dtypedtype, optionalData type of the output. Returns: aMaskedArrayA masked...
- numpy.ma.masked_all_like
...as the array arr, where all the data are masked. Parameters: arrndarrayAn array describing the shape and dtype of the required MaskedArray. Returns: aMaskedArrayA masked array with all data masked. Raises: AttributeErrorIf arr doe...
- numpy.ma.masked_array.astype
...onalBy default, astype always returns a newly allocated array. If this is set to false, and the dtype, order, and subok requirements are satisfied, the input array is returned instead of a copy. Returns: arr_tndarrayUnless copy is False...
- numpy.ma.masked_array.shape
...is inferred from the size of the array and the remaining dimensions. Reshaping an array in-place will fail if a copy is required. Warning Setting arr.shape is discouraged and may be deprecated in the future. Using ndarray.reshape is the p...
- numpy.ma.MaskedArray.astype
...onalBy default, astype always returns a newly allocated array. If this is set to false, and the dtype, order, and subok requirements are satisfied, the input array is returned instead of a copy. Returns: arr_tndarrayUnless copy is False...
- numpy.ma.MaskedArray.shape
...is inferred from the size of the array and the remaining dimensions. Reshaping an array in-place will fail if a copy is required. Warning Setting arr.shape is discouraged and may be deprecated in the future. Using ndarray.reshape is the p...
- numpy.matrix.astype
...onalBy default, astype always returns a newly allocated array. If this is set to false, and the dtype, order, and subok requirements are satisfied, the input array is returned instead of a copy. Returns: arr_tndarrayUnless copy is False...
- numpy.matrix.shape
...is inferred from the size of the array and the remaining dimensions. Reshaping an array in-place will fail if a copy is required. Warning Setting arr.shape is discouraged and may be deprecated in the future. Using ndarray.reshape is the p...
- numpy.memmap.astype
...onalBy default, astype always returns a newly allocated array. If this is set to false, and the dtype, order, and subok requirements are satisfied, the input array is returned instead of a copy. Returns: arr_tndarrayUnless copy is False...
- numpy.memmap.shape
...is inferred from the size of the array and the remaining dimensions. Reshaping an array in-place will fail if a copy is required. Warning Setting arr.shape is discouraged and may be deprecated in the future. Using ndarray.reshape is the p...
- numpy.nan_to_num
...y of x (True) or to replace values in-place (False). The in-place operation only occurs if casting to an array does not require a copy. Default is True. nanint, float, optionalValue to be used to fill NaN values. If no value is passed then...
- numpy.ndarray.astype
...onalBy default, astype always returns a newly allocated array. If this is set to false, and the dtype, order, and subok requirements are satisfied, the input array is returned instead of a copy. Returns: arr_tndarrayUnless copy is False...
- numpy.ndarray.shape
...is inferred from the size of the array and the remaining dimensions. Reshaping an array in-place will fail if a copy is required. Warning Setting arr.shape is discouraged and may be deprecated in the future. Using ndarray.reshape is the p...
- numpy.nditer
...te over. flagssequence of str, optionalFlags to control the behavior of the iterator. buffered enables buffering when required. c_index causes a C-order index to be tracked. f_index causes a Fortran-order index to be tracked. multi_index...
- numpy.nditer.remove_axis
...numpy.nditer.remove_axis method nditer.remove_axis(i, /) Removes axis i from the iterator. Requires that the flag “multi_index” be enabled....
- numpy.pad
...added at the end of vector. iaxisintThe axis currently being calculated. kwargsdictAny keyword arguments the function requires. Examples >>> import numpy as np >>> a = [1, 2, 3, 4, 5] >>> np.pad(a, (2, 3), 'constant', constant_values=(4...
- numpy.polynomial.chebyshev.chebdomain
...f elements in the array. itemsizeintThe memory use of each array element in bytes. nbytesintThe total number of bytes required to store the array data, i.e., itemsize * size. ndimintThe array’s number of dimensions. shapetuple of intsSh...
- numpy.polynomial.chebyshev.chebmul
...>>> from numpy.polynomial import chebyshev as C >>> c1 = (1,2,3) >>> c2 = (3,2,1) >>> C.chebmul(c1,c2) # multiplication requires "reprojection" array([ 6.5, 12. , 12. , 4. , 1.5])...
- numpy.polynomial.chebyshev.chebone
...f elements in the array. itemsizeintThe memory use of each array element in bytes. nbytesintThe total number of bytes required to store the array data, i.e., itemsize * size. ndimintThe array’s number of dimensions. shapetuple of intsSh...
- numpy.polynomial.chebyshev.chebx
...f elements in the array. itemsizeintThe memory use of each array element in bytes. nbytesintThe total number of bytes required to store the array data, i.e., itemsize * size. ndimintThe array’s number of dimensions. shapetuple of intsSh...
- numpy.polynomial.chebyshev.chebzero
...f elements in the array. itemsizeintThe memory use of each array element in bytes. nbytesintThe total number of bytes required to store the array data, i.e., itemsize * size. ndimintThe array’s number of dimensions. shapetuple of intsSh...
- numpy.polynomial.hermite.hermdomain
...f elements in the array. itemsizeintThe memory use of each array element in bytes. nbytesintThe total number of bytes required to store the array data, i.e., itemsize * size. ndimintThe array’s number of dimensions. shapetuple of intsSh...
- numpy.polynomial.hermite.hermone
...f elements in the array. itemsizeintThe memory use of each array element in bytes. nbytesintThe total number of bytes required to store the array data, i.e., itemsize * size. ndimintThe array’s number of dimensions. shapetuple of intsSh...
- numpy.polynomial.hermite.hermx
...f elements in the array. itemsizeintThe memory use of each array element in bytes. nbytesintThe total number of bytes required to store the array data, i.e., itemsize * size. ndimintThe array’s number of dimensions. shapetuple of intsSh...
- numpy.polynomial.hermite.hermzero
...f elements in the array. itemsizeintThe memory use of each array element in bytes. nbytesintThe total number of bytes required to store the array data, i.e., itemsize * size. ndimintThe array’s number of dimensions. shapetuple of intsSh...
- numpy.polynomial.hermite_e.hermedomain
...f elements in the array. itemsizeintThe memory use of each array element in bytes. nbytesintThe total number of bytes required to store the array data, i.e., itemsize * size. ndimintThe array’s number of dimensions. shapetuple of intsSh...
- numpy.polynomial.hermite_e.hermeone
...f elements in the array. itemsizeintThe memory use of each array element in bytes. nbytesintThe total number of bytes required to store the array data, i.e., itemsize * size. ndimintThe array’s number of dimensions. shapetuple of intsSh...
- numpy.polynomial.hermite_e.hermex
...f elements in the array. itemsizeintThe memory use of each array element in bytes. nbytesintThe total number of bytes required to store the array data, i.e., itemsize * size. ndimintThe array’s number of dimensions. shapetuple of intsSh...
- numpy.polynomial.hermite_e.hermezero
...f elements in the array. itemsizeintThe memory use of each array element in bytes. nbytesintThe total number of bytes required to store the array data, i.e., itemsize * size. ndimintThe array’s number of dimensions. shapetuple of intsSh...
- numpy.polynomial.laguerre.lagdomain
...f elements in the array. itemsizeintThe memory use of each array element in bytes. nbytesintThe total number of bytes required to store the array data, i.e., itemsize * size. ndimintThe array’s number of dimensions. shapetuple of intsSh...
- numpy.polynomial.laguerre.lagone
...f elements in the array. itemsizeintThe memory use of each array element in bytes. nbytesintThe total number of bytes required to store the array data, i.e., itemsize * size. ndimintThe array’s number of dimensions. shapetuple of intsSh...
- numpy.polynomial.laguerre.lagx
...f elements in the array. itemsizeintThe memory use of each array element in bytes. nbytesintThe total number of bytes required to store the array data, i.e., itemsize * size. ndimintThe array’s number of dimensions. shapetuple of intsSh...
- numpy.polynomial.laguerre.lagzero
...f elements in the array. itemsizeintThe memory use of each array element in bytes. nbytesintThe total number of bytes required to store the array data, i.e., itemsize * size. ndimintThe array’s number of dimensions. shapetuple of intsSh...
- numpy.polynomial.legendre.legdomain
...f elements in the array. itemsizeintThe memory use of each array element in bytes. nbytesintThe total number of bytes required to store the array data, i.e., itemsize * size. ndimintThe array’s number of dimensions. shapetuple of intsSh...
- numpy.polynomial.legendre.legmul
...les >>> from numpy.polynomial import legendre as L >>> c1 = (1,2,3) >>> c2 = (3,2) >>> L.legmul(c1,c2) # multiplication requires "reprojection" array([ 4.33333333, 10.4 , 11.66666667, 3.6 ]) # may vary...
- numpy.polynomial.legendre.legone
...f elements in the array. itemsizeintThe memory use of each array element in bytes. nbytesintThe total number of bytes required to store the array data, i.e., itemsize * size. ndimintThe array’s number of dimensions. shapetuple of intsSh...
- numpy.polynomial.legendre.legx
...f elements in the array. itemsizeintThe memory use of each array element in bytes. nbytesintThe total number of bytes required to store the array data, i.e., itemsize * size. ndimintThe array’s number of dimensions. shapetuple of intsSh...
- numpy.polynomial.legendre.legzero
...f elements in the array. itemsizeintThe memory use of each array element in bytes. nbytesintThe total number of bytes required to store the array data, i.e., itemsize * size. ndimintThe array’s number of dimensions. shapetuple of intsSh...
- numpy.polynomial.polynomial.polydomain
...f elements in the array. itemsizeintThe memory use of each array element in bytes. nbytesintThe total number of bytes required to store the array data, i.e., itemsize * size. ndimintThe array’s number of dimensions. shapetuple of intsSh...
- numpy.polynomial.polynomial.polyone
...f elements in the array. itemsizeintThe memory use of each array element in bytes. nbytesintThe total number of bytes required to store the array data, i.e., itemsize * size. ndimintThe array’s number of dimensions. shapetuple of intsSh...
- numpy.polynomial.polynomial.polyx
...f elements in the array. itemsizeintThe memory use of each array element in bytes. nbytesintThe total number of bytes required to store the array data, i.e., itemsize * size. ndimintThe array’s number of dimensions. shapetuple of intsSh...
- numpy.polynomial.polynomial.polyzero
...f elements in the array. itemsizeintThe memory use of each array element in bytes. nbytesintThe total number of bytes required to store the array data, i.e., itemsize * size. ndimintThe array’s number of dimensions. shapetuple of intsSh...
- numpy.polynomial.polyutils.mapparms
...See also getdomain, mapdomain Notes Also works for complex numbers, and thus can be used to calculate the parameters required to map any line in the complex plane to any other line therein. Examples >>> from numpy.polynomial import polyu...
- numpy.random.BitGenerator.state
...The base BitGenerator.state must be overridden by a subclass Returns: statedictDictionary containing the information required to describe the state of the PRNG...
- numpy.random.Generator.noncentral_f
...dia.org/wiki/Noncentral_F-distribution Examples In a study, testing for a specific alternative to the null hypothesis requires use of the Noncentral F distribution. We need to calculate the area in the tail of the distribution that exceed...
- numpy.random.MT19937.state
...te attribute random.MT19937.state Get or set the PRNG state Returns: statedictDictionary containing the information required to describe the state of the PRNG...
- numpy.random.noncentral_f
...dia.org/wiki/Noncentral_F-distribution Examples In a study, testing for a specific alternative to the null hypothesis requires use of the Noncentral F distribution. We need to calculate the area in the tail of the distribution that exceed...
- numpy.random.PCG64.advance
...values are simulated using a rejection-based method and so, on average, more than one value from the underlying RNG is required to generate an single draw. The number of bits required to generate a simulated value differs from the number o...
- numpy.random.PCG64.state
...tate attribute random.PCG64.state Get or set the PRNG state Returns: statedictDictionary containing the information required to describe the state of the PRNG...
- numpy.random.PCG64DXSM.advance
...values are simulated using a rejection-based method and so, on average, more than one value from the underlying RNG is required to generate an single draw. The number of bits required to generate a simulated value differs from the number o...
- numpy.random.PCG64DXSM.state
...attribute random.PCG64DXSM.state Get or set the PRNG state Returns: statedictDictionary containing the information required to describe the state of the PRNG...
- numpy.random.Philox.advance
...values are simulated using a rejection-based method and so, on average, more than one value from the underlying RNG is required to generate an single draw. The number of bits required to generate a simulated value differs from the number o...
- numpy.random.Philox.state
...ate attribute random.Philox.state Get or set the PRNG state Returns: statedictDictionary containing the information required to describe the state of the PRNG...
- numpy.random.RandomState.noncentral_f
...dia.org/wiki/Noncentral_F-distribution Examples In a study, testing for a specific alternative to the null hypothesis requires use of the Noncentral F distribution. We need to calculate the area in the tail of the distribution that exceed...
- numpy.random.SFC64.state
...tate attribute random.SFC64.state Get or set the PRNG state Returns: statedictDictionary containing the information required to describe the state of the PRNG...
- numpy.rec.fromstring
...> np.rec.fromstring(s, dtype='u1,u1,u1,S3') Traceback (most recent call last): ... TypeError: a bytes-like object is required, not 'str'...
- numpy.recarray.astype
...onalBy default, astype always returns a newly allocated array. If this is set to false, and the dtype, order, and subok requirements are satisfied, the input array is returned instead of a copy. Returns: arr_tndarrayUnless copy is False...
- numpy.recarray.shape
...is inferred from the size of the array and the remaining dimensions. Reshaping an array in-place will fail if a copy is required. Warning Setting arr.shape is discouraged and may be deprecated in the future. Using ndarray.reshape is the p...
- numpy.require
...NumPy reference Routines and objects by topic Array manipulation routines numpy.require...
- numpy.reshape
...rd compatibility. copybool, optionalIf True, then the array data is copied. If None, a copy will only be made if it’s required by order. For False it raises a ValueError if a copy cannot be avoided. Default: None. Returns: reshaped_ar...
- numpy.resize
...ns: reshaped_arrayndarrayThe new array is formed from the data in the old array, repeated if necessary to fill out the required number of elements. The data are repeated iterating over the array in C-order. See also numpy.reshapeRes...
- numpy.save
...d portability (pickled objects may not be loadable on different Python installations, for example if the stored objects require libraries that are not available, and not all pickled data is compatible between different versions of Python)....
- numpy.savez
...d portability (pickled objects may not be loadable on different Python installations, for example if the stored objects require libraries that are not available, and not all pickled data is compatible between different versions of Python)....
- numpy.savez_compressed
...d portability (pickled objects may not be loadable on different Python installations, for example if the stored objects require libraries that are not available, and not all pickled data is compatible between different versions of Python)....
- numpy.searchsorted
...Return a sorted copy of an array. histogramProduce histogram from 1-D data. Notes Binary search is used to find the required insertion points. As of NumPy 1.4.0 searchsorted works with real/complex arrays containing nan values. The enha...
- numpy.sqrt
...turn the non-negative square-root of an array, element-wise. Parameters: xarray_likeThe values whose square-roots are required. outndarray, None, or tuple of ndarray and None, optionalA location into which the result is stored. If provid...
- numpy.ufunc.at
...dimensions, indices can be a tuple of array like index objects or slice objects. barray_likeSecond operand for ufuncs requiring two operands. Operand must be broadcastable over first operand after indexing or slicing. Examples Set ite...
- numpy.ufunc.resolve_dtypes
...e for the calculation. Note that dtypes may not match the passed in ones (casting is necessary). Examples This API requires passing dtypes, define them for convenience: >>> import numpy as np >>> int32 = np.dtype("int32") >>> float32 =...
- NumPy: the absolute basics for beginners
...handles NumPy files with a .npz file extension. The .npy and .npz files store data, shape, dtype, and other information required to reconstruct the ndarray in a way that allows the array to be correctly retrieved, even when the file is on a...
- NumPy’s module structure
...NumPy’s module structure NumPy has a large number of submodules. Most regular usage of NumPy requires only the main namespace and a smaller set of submodules. The rest either either special-purpose or niche namesp...
- Packaging (
numpy.distutils
)...he command arguments, to managing the relation between the CPU baseline and dispatch-able features, also generating the required C headers and ending with compiling the sources with proper compiler's flags. cpuinfo.cpu core.Extension(nam...
- Python types and C-structures
...r to the PyArray_Type typeobject. type PyArrayObject type NPY_AO The PyArrayObject C-structure contains all of the required information for an array. All instances of an ndarray (and its subclasses) will have this structure. For futur...
- Random sampling (
numpy.random
)...ates between the user’s input and the internal implementation details of each BitGenerator algorithm, each of which can require different amounts of bits for its state. Importantly, it lets you use arbitrary-sized integers and arbitrary seq...
- Reading and writing files
...the 2 in row 1), the last column can be less than width (for example, the 6 # in row 2), and no delimiting character is required (for instance 8888 and 9 # in row 3) >>> with open("fixedwidth.txt", "r") as f: ... data = (f.read()) >>> p...
- Releasing a version
...actions. Building docs We are no longer building PDF files. All that will be needed is virtualenv (pip). The other requirements will be filled automatically during the documentation build process. Uploading to PyPI The only applicati...
- Standard array subclasses
...question is by asking yourself if the object you are interested in can be replaced as a single array or does it really require two or more arrays at its core. Note that asarray always returns the base-class ndarray. If you are confident th...
- Status of
numpy.distutils
and migration advice...s incompatible changes in setuptools. Whatever you do, it is recommended to put an upper bound on your setuptools build requirement in pyproject.toml to avoid future breakage - see For downstream package authors....
- Testing guidelines
...utually-broadcastable shapes). The advantages over random generation include tools to replay and share failures without requiring a fixed seed, reporting minimal examples for each failure, and better-than-naive-random techniques for trigger...
- Testing the numpy.i typemaps
...nt argument signatures, for a total of 888 typemaps supported “out of the box”. Each of these typemaps, in turn, might require several unit tests in order to verify expected behavior for both proper and improper inputs. Currently, this re...
- The
numpy.ma
module...ely satisfactory if some entries have been marked as invalid. As a general rule, where a representation of the array is required without any masked entries, it is recommended to fill the array with the filled method. Accessing the mask Th...
- Using F2PY
...portability and compiler independence. --[no-]freethreading-compatibleCreate a module that declares it does or doesn’t require the GIL. The default is --no-freethreading-compatible for backwards compatibility. Inspect the fortran code you...
- Using NumPy C-API
...Using NumPy C-API How to extend NumPy Writing an extension module Required subroutine Defining functions Functions without keyword arguments Functions with keyword arguments Reference co...
- Verifying bugs and bug fixes in NumPy
...a pre-built wheel installed in your virtual environment via pip will suffice: pip install numpy==1.18.4 Some bugs may require you to build the NumPy version referenced in the issue report. To learn how to do that, visit Building from sour...
- What is NumPy?
...Changing the size of an ndarray will create a new array and delete the original. The elements in a NumPy array are all required to be of the same data type, and thus will be the same size in memory. The exception: one can have arrays of (...
- Writing your own ufunc
...conversions with minimal memory usage optional output arrays It is not difficult to create your own ufunc. All that is required is a 1-d loop for each data-type you want to support. Each 1-d loop must have a specific signature, and only uf...
- numpy.lib.recfunctions.require_fields (Python function, in Structured arrays)
- Advanced debugging tools
...any improvements or suggestions to these workflows. Finding C errors with additional tooling Most development will not require more than a typical debugging toolchain as shown in Debugging. But for example memory leaks can be particularly...
- Advanced F2PY use cases
...fied below. If the length of the character*(*) output argument is determined by the state of other input arguments, the required connection can be established in a signature file or within a f2py-comment by adding an extra declaration for t...
- Array API
...From other objects PyObject *PyArray_FromAny(PyObject *op, PyArray_Descr *dtype, int min_depth, int max_depth, int requirements, PyObject *context) This is the main function used to obtain an array from any nested sequence, or object t...
- Beyond the basics
...else has thought. — Albert Szent-Gyorgi Iterating over elements in the array Basic iteration One common algorithmic requirement is to be able to walk over all elements in a multidimensional array. The array iterator object makes this ea...
- Broadcasting
...height of an athlete to be classified. The codes represent different classes of athletes. [1] Finding the closest point requires calculating the distance between observation and each of the codes. The shortest distance provides the best mat...
- Building redistributable binaries
...al binary may be a wheel - in that case, run auditwheel (Linux), delocate (macOS) or delvewheel (Windows) to vendor the required shared libraries into the wheel. The final binary may also be in another packaging format (e.g., a .rpm, .deb o...
- C API deprecations
...e data of ndarrays, this will not remove this ability. Rather, there are many potential performance optimizations which require changing the implementation details, and NumPy developers have been unable to try them because of the high value...
- C API for random
...0.0 to 1.0 “fill” functions will fill the provided out with cnt values. The functions without “standard” in their name require additional parameters to describe the distributions. Functions with inv in their name are based on the slower in...
- Copies and views
...mes non-contiguous (perhaps after a ndarray.transpose operation), the reshaping cannot be done by modifying strides and requires a copy. In these cases, we can raise an error by assigning the new shape to the shape attribute of the array. F...
- Cross compilation
...ompilation based on crossenv is known to work, as used (for example) in conda-forge. Cross-compilation without crossenv requires some manual overrides. You instruct these overrides by passing options to meson setup via meson-python. All dis...
- Data type API
...a list of enumerated types defined providing the basic 25 data types plus some useful generic names. Whenever the code requires a type number, one of these enumerated types is requested. The types are all called NPY_{NAME}: enumerator NP...
- Data type objects (
dtype
)...d'> >>> type(x[1]['grades']) <class 'numpy.ndarray'> Specifying and constructing data types Whenever a data-type is required in a NumPy function or method, either a dtype object or something that can be converted to one can be supplied....
- Development workflow
...following conditions: by a weekly cron job or if the GitHub Actions or Cirrus build has been manually triggered, which requires appropriate permissions The wheels will be uploaded to https://anaconda.org/multibuild-wheels-staging/ if the...
- Extending
...Cython. The Generator object can also be used with user-provided BitGenerators as long as these export a small set of required functions. Numba Numba can be used with either CTypes or CFFI. The current iteration of the BitGenerators all...
- Extending via Numba and CFFI
...Extending via Numba and CFFI r""" Building the required library in this example requires a source distribution of NumPy or clone of the NumPy git repository since dist...
- F2PY and build systems
...ists of: Fortran source(s) One or more generated files from f2py A C wrapper file is always created Code with modules require an additional .f90 wrapper Code with functions generate an additional .f wrapper fortranobject.{c,h} Distribu...
- F2PY and Windows Intel Fortran
...disassembly of components and liability. Neither the Python Intel installation nor the Classic Intel C/C++ Compiler are required. The Intel Fortran Compilers come in a combined installer providing both Classic and Beta versions; these als...
- F2PY examples
...and the integer argument should be mapped to a C integer. The interface will attempt to convert all arguments to their required types (and shapes) and issue an error if unsuccessful. However, because f2py knows nothing about the semantics...
- Generalized universal function API
...ns in an output will be determined by the size of a core dimension with the same label in an input array. This is not a requirement, and it is possible to define a signature where a label comes up for the first time in an output, although s...
- How does the CPU dispatcher work?
...definitions that affect the code paths. This enables certain instruction-sets for each compiled object depending on the required optimizations and ends with linking the returned objects together. This mechanism should support all compile...
- Importing data with
genfromtxt
...sufficient to define how the sequence of strings must be converted. However, some additional control may sometimes be required. For example, we may want to make sure that a date in a format YYYY/MM/DD is converted to a datetime object, o...
- Indexing on
ndarrays
..., 3, 1) >>> x[:, None, :, :].shape (2, 1, 3, 1) This can be handy to combine two arrays in a way that otherwise would require explicit reshaping operations. For example: >>> x = np.arange(5) >>> x[:, np.newaxis] + x[np.newaxis, :] array([...
- Iterating over arrays
...2], [-1, 0, 1]]) Tracking an index or multi-index is incompatible with using an external loop, because it requires a different index value per element. If you try to combine these flags, the nditer object will raise an excepti...
- meson.build
...get_compiler('cython') # Keep synced with pyproject.toml if not cy.version().version_compare('>=3.0.6') error('tests requires Cython >= 3.0.6') endif base_cython_args = [] if cy.version().version_compare('>=3.1.0') base_cython_args +=...
- Multithreaded generation
...igned). Under normal circumstances, arrays created using the common constructors such as numpy.empty will satisfy these requirements. This example makes use of Python 3 concurrent.futures to fill an array using multiple threads. Threads ar...
- NpyString API
...NpyString_release_allocator must be called on the allocator returned by this function exactly once. Note that functions requiring the GIL should not be called while the allocator mutex is held, as doing so may cause deadlocks. void NpyS...
- Parallel random number generation
...oot seed as a list of integers eliminates this risk. Lazy seeding practices will still be fairly safe. This scheme does require that the extra IDs be unique and deterministically created. This may require coordination between the worker pro...
- Performance
...e in ns to produce 1 random value from a specific distribution. The original MT19937 generator is much slower since it requires 2 32-bit values to equal the output of the faster generators. Integer performance has a similar ordering. The p...
- Reviewer guidelines
...adding it to the release notes. When merging contributions, a committer is responsible for ensuring that those meet the requirements outlined in the Development process guidelines for NumPy. Also, check that new features and backwards compa...
- Setting up and using your development environment
...cessary compilers and Python development headers installed - see Building from source. Building NumPy as of version 2.0 requires C11 and C++17 compliant compilers. Having compiled code also means that importing NumPy from the development so...
- Signature file
...an routine signature F2PY generates a Python/C extension function that has the following signature: def <routine name>(<required arguments>[,<optional arguments>]): ... return <return variables> The signature of a Fortran block...
- Structured arrays
...n since it allows control over the byte-offsets of the fields and the itemsize of the structure. The dictionary has two required keys, ‘names’ and ‘formats’, and four optional keys, ‘offsets’, ‘itemsize’, ‘aligned’ and ‘titles’. The values...
- Subclassing ndarray
...ining a specific __array_wrap__ method for our subclass, we can tweak the output from ufuncs. The __array_wrap__ method requires self, then an argument - which is the result of the ufunc or another NumPy function - and an optional parameter...
- The array interface protocol
...e consists of the object having an __array_interface__ attribute. object.__array_interface__ A dictionary of items (3 required and 5 optional). The optional keys in the dictionary have implied defaults if they are not provided. The keys...
- The N-dimensional array (
ndarray
)...s in a different scheme. Note Several algorithms in NumPy work on arbitrarily strided arrays. However, some algorithms require single-segment arrays. When an irregularly strided array is passed in to such algorithms, a copy is automaticall...
- Three ways to wrap - getting started
...nts in Python may lead to difficult to find bugs, not to mention the fact that the codes will be less readable when all required type checks are implemented. Though the approach to wrapping Fortran routines for Python discussed so far is v...
- ufunc API
...niversal function code to only release the Python GIL if loop->obj is not true (i.e. this is not an OBJECT array loop). Requires use of NPY_BEGIN_THREADS_DEF in variable declaration area. NPY_LOOP_END_THREADS Used in universal function...
- Universal functions (
ufunc
)..., where, casting, order, ...]) Convert angles from radians to degrees. Bit-twiddling functions These function all require integer arguments and they manipulate the bit-pattern of those arguments. bitwise_and(x1, x2, /[, out, where,...
- Using F2PY bindings in Python
...first element of the sequence object is passed to the Fortran routine as a scalar argument. Note When type-casting is required and there is possible loss of information via narrowing e.g. when type-casting float to integer or complex to f...
- Using Python as glue
...ith compiled code while still allowing for separate distribution of the extension module. The only draw-back is that it requires the existence of a Fortran compiler in order for a user to install the code. However, with the existence of the...
- Using via
cmake
...is fib1module.c, which is beneficial. With this; we can now initialize a CMakeLists.txt file as follows: cmake_minimum_required(VERSION 3.18) # Needed to avoid requiring embedded Python libs too project(fibby VERSION 1.0 DESCRIPTION "...
- Using via
meson
....f2py fib1.f -m fib2 meson --wipe builddir meson compile -C builddir cd builddir python -c 'import fib2' However this requires the ability to modify the source which is not always possible. The easiest way to solve this is to let f2py dea...
- Using via
scikit-build
...uments are to move away from the internal numpy.distutils methods. For situations where no setuptools replacements are required or wanted (i.e. if wheels are not needed), it is recommended to instead use the vanilla cmake setup described i...
- What’s new or different
...ere is a quick comparison of the two implementations. Feature Older Equivalent Notes Generator RandomState Generator requires a stream source, called a BitGenerator A number of these are provided. RandomState uses the Mersenne Twister MT...
- Working with Arrays of Strings And Bytes
...dictable length. In these cases it is awkward to use fixed-width strings, since storing all the data without truncation requires knowing the length of the longest string one would like to store in the array before the array is created. To s...