NumPy 1.8.0 Release Notes#
This release supports Python 2.6 -2.7 and 3.2 - 3.3.
Highlights#
New, no 2to3, Python 2 and Python 3 are supported by a common code base.
New, gufuncs for linear algebra, enabling operations on stacked arrays.
New, inplace fancy indexing for ufuncs with the
.atmethod.New,
partitionfunction, partial sorting via selection for fast median.New,
nanmean,nanvar, andnanstdfunctions skipping NaNs.New,
fullandfull_likefunctions to create value initialized arrays.New,
PyUFunc_RegisterLoopForDescr, better ufunc support for user dtypes.Numerous performance improvements in many areas.
Dropped Support#
Support for Python versions 2.4 and 2.5 has been dropped,
Support for SCons has been removed.
Future Changes#
The Datetime64 type remains experimental in this release. In 1.9 there willprobably be some changes to make it more usable.
The diagonal method currently returns a new array and raises aFutureWarning. In 1.9 it will return a readonly view.
Multiple field selection from an array of structured type currentlyreturns a new array and raises a FutureWarning. In 1.9 it will return areadonly view.
The numpy/oldnumeric and numpy/numarray compatibility modules will beremoved in 1.9.
Compatibility notes#
The doc/sphinxext content has been moved into its own github repository,and is included in numpy as a submodule. See the instructions indoc/HOWTO_BUILD_DOCS.rst for how to access the content.
The hash function of numpy.void scalars has been changed. Previously thepointer to the data was hashed as an integer. Now, the hash function usesthe tuple-hash algorithm to combine the hash functions of the elements ofthe scalar, but only if the scalar is read-only.
Numpy has switched its build system to using ‘separate compilation’ bydefault. In previous releases this was supported, but not default. Thisshould produce the same results as the old system, but if you’re trying todo something complicated like link numpy statically or using an unusualcompiler, then it’s possible you will encounter problems. If so, pleasefile a bug and as a temporary workaround you can re-enable the old buildsystem by exporting the shell variable NPY_SEPARATE_COMPILATION=0.
For the AdvancedNew iterator theoa_ndim flag should now be -1 to indicatethat noop_axes anditershape are passed in. Theoa_ndim==0case, now indicates a 0-D iteration andop_axes being NULL and the oldusage is deprecated. This does not effect theNpyIter_New orNpyIter_MultiNew functions.
The functions nanargmin and nanargmax now return np.iinfo[‘intp’].min forthe index in all-NaN slices. Previously the functions would raise a ValueErrorfor array returns and NaN for scalar returns.
NPY_RELAXED_STRIDES_CHECKING#
There is a new compile time environment variableNPY_RELAXED_STRIDES_CHECKING. If this variable is set to 1, thennumpy will consider more arrays to be C- or F-contiguous – forexample, it becomes possible to have a column vector which isconsidered both C- and F-contiguous simultaneously. The new definitionis more accurate, allows for faster code that makes fewer unnecessarycopies, and simplifies numpy’s code internally. However, it may alsobreak third-party libraries that make too-strong assumptions about thestride values of C- and F-contiguous arrays. (It is also currentlyknown that this breaks Cython code using memoryviews, which will befixed in Cython.) THIS WILL BECOME THE DEFAULT IN A FUTURE RELEASE, SOPLEASE TEST YOUR CODE NOW AGAINST NUMPY BUILT WITH:
NPY_RELAXED_STRIDES_CHECKING=1pythonsetup.pyinstall
You can check whether NPY_RELAXED_STRIDES_CHECKING is in effect byrunning:
np.ones((10,1),order="C").flags.f_contiguous
This will beTrue if relaxed strides checking is enabled, andFalse otherwise. The typical problem we’ve seen so far is C codethat works with C-contiguous arrays, and assumes that the itemsize canbe accessed by looking at the last element in thePyArray_STRIDES(arr)array. When relaxed strides are in effect, this is not true (and infact, it never was true in some corner cases). Instead, usePyArray_ITEMSIZE(arr).
For more information check the “Internal memory layout of an ndarray”section in the documentation.
Binary operations with non-arrays as second argument#
Binary operations of the form<array-or-subclass>*<non-array-subclass>where<non-array-subclass> declares an__array_priority__ higher thanthat of<array-or-subclass> will now unconditionally returnNotImplemented, giving<non-array-subclass> a chance to handle theoperation. Previously,NotImplemented would only be returned if<non-array-subclass> actually implemented the reversed operation, and aftera (potentially expensive) array conversion of<non-array-subclass> had beenattempted. (bug,pull request)
Functionmedian used withoverwrite_input only partially sorts array#
Ifmedian is used withoverwrite_input option the input array will now onlybe partially sorted instead of fully sorted.
Fix to financial.npv#
The npv function had a bug. Contrary to what the documentation stated, itsummed from indexes1 toM instead of from0 toM-1. Thefix changes the returned value. The mirr function called the npv function,but worked around the problem, so that was also fixed and the return valueof the mirr function remains unchanged.
Runtime warnings when comparing NaN numbers#
ComparingNaN floating point numbers now raises theinvalid runtimewarning. If aNaN is expected the warning can be ignored using np.errstate.E.g.:
withnp.errstate(invalid='ignore'):operation()
New Features#
Support for linear algebra on stacked arrays#
The gufunc machinery is now used for np.linalg, allowing operations onstacked arrays and vectors. For example:
>>>aarray([[[ 1., 1.], [ 0., 1.]], [[ 1., 1.], [ 0., 1.]]])>>>np.linalg.inv(a)array([[[ 1., -1.], [ 0., 1.]], [[ 1., -1.], [ 0., 1.]]])
In place fancy indexing for ufuncs#
The functionat has been added to ufunc objects to allow in placeufuncs with no buffering when fancy indexing is used. For example, thefollowing will increment the first and second items in the array, and willincrement the third item twice:numpy.add.at(arr,[0,1,2,2],1)
This is what many have mistakenly thoughtarr[[0,1,2,2]]+=1 would do,but that does not work as the incremented value ofarr[2] is simply copiedinto the third slot inarr twice, not incremented twice.
New functionspartition andargpartition#
New functions to partially sort arrays via a selection algorithm.
Apartition by indexk moves thek smallest element to the front ofan array. All elements beforek are then smaller or equal than the valuein positionk and all elements followingk are then greater or equalthan the value in positionk. The ordering of the values within thesebounds is undefined.A sequence of indices can be provided to sort all of them into their sortedposition at once iterative partitioning.This can be used to efficiently obtain order statistics like median orpercentiles of samples.partition has a linear time complexity ofO(n) while a full sort hasO(nlog(n)).
New functionsnanmean,nanvar andnanstd#
New nan aware statistical functions are added. In these functions theresults are what would be obtained if nan values were omitted from allcomputations.
New functionsfull andfull_like#
New convenience functions to create arrays filled with a specific value;complementary to the existingzeros andzeros_like functions.
IO compatibility with large files#
Large NPZ files >2GB can be loaded on 64-bit systems.
Building against OpenBLAS#
It is now possible to build numpy against OpenBLAS by editing site.cfg.
New constant#
Euler’s constant is now exposed in numpy as euler_gamma.
New modes for qr#
New modes ‘complete’, ‘reduced’, and ‘raw’ have been added to the qrfactorization and the old ‘full’ and ‘economic’ modes are deprecated.The ‘reduced’ mode replaces the old ‘full’ mode and is the default as wasthe ‘full’ mode, so backward compatibility can be maintained by notspecifying the mode.
The ‘complete’ mode returns a full dimensional factorization, which can beuseful for obtaining a basis for the orthogonal complement of the rangespace. The ‘raw’ mode returns arrays that contain the Householderreflectors and scaling factors that can be used in the future to apply qwithout needing to convert to a matrix. The ‘economic’ mode is simplydeprecated, there isn’t much use for it and it isn’t any more efficientthan the ‘raw’ mode.
Newinvert argument toin1d#
The functionin1d now accepts ainvert argument which, whenTrue,causes the returned array to be inverted.
Advanced indexing usingnp.newaxis#
It is now possible to usenp.newaxis/None together with indexarrays instead of only in simple indices. This means thatarray[np.newaxis,[0,1]] will now work as expected and select the firsttwo rows while prepending a new axis to the array.
C-API#
New ufuncs can now be registered with builtin input types and a customoutput type. Before this change, NumPy wouldn’t be able to find the rightufunc loop function when the ufunc was called from Python, because the ufuncloop signature matching logic wasn’t looking at the output operand type.Now the correct ufunc loop is found, as long as the user provides an outputargument with the correct output type.
runtests.py#
A simple test runner scriptruntests.py was added. It also builds Numpy viasetup.pybuild and can be used to run tests easily during development.
Improvements#
IO performance improvements#
Performance in reading large files was improved by chunking (see also IO compatibility).
Performance improvements topad#
Thepad function has a new implementation, greatly improving performance forall inputs exceptmode= (retained for backwards compatibility).Scaling with dimensionality is dramatically improved for rank >= 4.
Performance improvements toisnan,isinf,isfinite andbyteswap#
isnan,isinf,isfinite andbyteswap have been improved to takeadvantage of compiler builtins to avoid expensive calls to libc.This improves performance of these operations by about a factor of two on gnulibc systems.
Performance improvements via SSE2 vectorization#
Several functions have been optimized to make use of SSE2 CPU SIMD instructions.
- Float32 and float64:
base math (add,subtract,divide,multiply)
sqrt
minimum/maximum
absolute
- Bool:
logical_or
logical_and
logical_not
This improves performance of these operations up to 4x/2x for float32/float64and up to 10x for bool depending on the location of the data in the CPU caches.The performance gain is greatest for in-place operations.
In order to use the improved functions the SSE2 instruction set must be enabledat compile time. It is enabled by default on x86_64 systems. On x86_32 with acapable CPU it must be enabled by passing the appropriate flag to the CFLAGSbuild variable (-msse2 with gcc).
Performance improvements tomedian#
median is now implemented in terms ofpartition instead ofsort whichreduces its time complexity from O(n log(n)) to O(n).If used with theoverwrite_input option the array will now only be partiallysorted instead of fully sorted.
Overridable operand flags in ufunc C-API#
When creating a ufunc, the default ufunc operand flags can be overriddenvia the new op_flags attribute of the ufunc object. For example, to setthe operand flag for the first input to read/write:
PyObject *ufunc = PyUFunc_FromFuncAndData(…);ufunc->op_flags[0] = NPY_ITER_READWRITE;
This allows a ufunc to perform an operation in place. Also, global nditer flagscan be overridden via the new iter_flags attribute of the ufunc object.For example, to set the reduce flag for a ufunc:
ufunc->iter_flags = NPY_ITER_REDUCE_OK;
Changes#
General#
The function np.take now allows 0-d arrays as indices.
The separate compilation mode is now enabled by default.
Several changes to np.insert and np.delete:
Previously, negative indices and indices that pointed past the end ofthe array were simply ignored. Now, this will raise a Future or DeprecationWarning. In the future they will be treated like normal indexing treatsthem – negative indices will wrap around, and out-of-bound indices willgenerate an error.
Previously, boolean indices were treated as if they were integers (alwaysreferring to either the 0th or 1st item in the array). In the future, theywill be treated as masks. In this release, they raise a FutureWarningwarning of this coming change.
In Numpy 1.7. np.insert already allowed the syntaxnp.insert(arr, 3, [1,2,3]) to insert multiple items at a single position.In Numpy 1.8. this is also possible fornp.insert(arr, [3], [1, 2, 3]).
Padded regions from np.pad are now correctly rounded, not truncated.
C-API Array Additions#
Four new functions have been added to the array C-API.
PyArray_Partition
PyArray_ArgPartition
PyArray_SelectkindConverter
PyDataMem_NEW_ZEROED
C-API Ufunc Additions#
One new function has been added to the ufunc C-API that allows to registeran inner loop for user types using the descr.
PyUFunc_RegisterLoopForDescr
C-API Developer Improvements#
ThePyArray_Type instance creation functiontp_new nowusestp_basicsize to determine how much memory to allocate.In previous releases onlysizeof(PyArrayObject) bytes ofmemory were allocated, often requiring C-API subtypes toreimplementtp_new.
Deprecations#
The ‘full’ and ‘economic’ modes of qr factorization are deprecated.
General#
The use of non-integer for indices and most integer arguments has beendeprecated. Previously float indices and function arguments such as axes orshapes were truncated to integers without warning. For examplearr.reshape(3., -1) orarr[0.] will trigger a deprecation warning inNumPy 1.8., and in some future version of NumPy they will raise an error.
Authors#
This release contains work by the following people who contributed at leastone patch to this release. The names are in alphabetical order by first name:
87
Adam Ginsburg +
Adam Griffiths +
Alexander Belopolsky +
Alex Barth +
Alex Ford +
Andreas Hilboll +
Andreas Kloeckner +
Andreas Schwab +
Andrew Horton +
argriffing +
Arink Verma +
Bago Amirbekian +
Bartosz Telenczuk +
bebert218 +
Benjamin Root +
Bill Spotz +
Bradley M. Froehle
Carwyn Pelley +
Charles Harris
Chris
Christian Brueffer +
Christoph Dann +
Christoph Gohlke
Dan Hipschman +
Daniel +
Dan Miller +
daveydave400 +
David Cournapeau
David Warde-Farley
Denis Laxalde
dmuellner +
Edward Catmur +
Egor Zindy +
endolith
Eric Firing
Eric Fode
Eric Moore +
Eric Price +
Fazlul Shahriar +
Félix Hartmann +
Fernando Perez
Frank B +
Frank Breitling +
Frederic
Gabriel
GaelVaroquaux
Guillaume Gay +
Han Genuit
HaroldMills +
hklemm +
jamestwebber +
Jason Madden +
Jay Bourque
jeromekelleher +
Jesús Gómez +
jmozmoz +
jnothman +
Johannes Schönberger +
John Benediktsson +
John Salvatier +
John Stechschulte +
Jonathan Waltman +
Joon Ro +
Jos de Kloe +
Joseph Martinot-Lagarde +
Josh Warner (Mac) +
Jostein Bø Fløystad +
Juan Luis Cano Rodríguez +
Julian Taylor +
Julien Phalip +
K.-Michael Aye +
Kumar Appaiah +
Lars Buitinck
Leon Weber +
Luis Pedro Coelho
Marcin Juszkiewicz
Mark Wiebe
Marten van Kerkwijk +
Martin Baeuml +
Martin Spacek
Martin Teichmann +
Matt Davis +
Matthew Brett
Maximilian Albert +
m-d-w +
Michael Droettboom
mwtoews +
Nathaniel J. Smith
Nicolas Scheffer +
Nils Werner +
ochoadavid +
Ondřej Čertík
ovillellas +
Paul Ivanov
Pauli Virtanen
peterjc
Ralf Gommers
Raul Cota +
Richard Hattersley +
Robert Costa +
Robert Kern
Rob Ruana +
Ronan Lamy
Sandro Tosi
Sascha Peilicke +
Sebastian Berg
Skipper Seabold
Stefan van der Walt
Steve +
Takafumi Arakaki +
Thomas Robitaille +
Tomas Tomecek +
Travis E. Oliphant
Valentin Haenel
Vladimir Rutsky +
Warren Weckesser
Yaroslav Halchenko
Yury V. Zaytsev +
A total of 119 people contributed to this release.People with a “+” by their names contributed a patch for the first time.