1========================== 2NumPy 1.14.0 Release Notes 3========================== 4 5Numpy 1.14.0 is the result of seven months of work and contains a large number 6of bug fixes and new features, along with several changes with potential 7compatibility issues. The major change that users will notice are the 8stylistic changes in the way numpy arrays and scalars are printed, a change 9that will affect doctests. See below for details on how to preserve the 10old style printing when needed. 11 12A major decision affecting future development concerns the schedule for 13dropping Python 2.7 support in the runup to 2020. The decision has been made to 14support 2.7 for all releases made in 2018, with the last release being 15designated a long term release with support for bug fixes extending through 162019. In 2019 support for 2.7 will be dropped in all new releases. More details 17can be found in `NEP 12`_. 18 19This release supports Python 2.7 and 3.4 - 3.6. 20 21.. _`NEP 12`: http://www.numpy.org/neps/nep-0014-dropping-python2.7-proposal.html 22 23 24Highlights 25========== 26 27* The `np.einsum` function uses BLAS when possible 28 29* ``genfromtxt``, ``loadtxt``, ``fromregex`` and ``savetxt`` can now handle 30 files with arbitrary Python supported encoding. 31 32* Major improvements to printing of NumPy arrays and scalars. 33 34 35New functions 36============= 37 38* ``parametrize``: decorator added to numpy.testing 39 40* ``chebinterpolate``: Interpolate function at Chebyshev points. 41 42* ``format_float_positional`` and ``format_float_scientific`` : format 43 floating-point scalars unambiguously with control of rounding and padding. 44 45* ``PyArray_ResolveWritebackIfCopy`` and ``PyArray_SetWritebackIfCopyBase``, 46 new C-API functions useful in achieving PyPy compatibility. 47 48 49Deprecations 50============ 51 52* Using ``np.bool_`` objects in place of integers is deprecated. Previously 53 ``operator.index(np.bool_)`` was legal and allowed constructs such as 54 ``[1, 2, 3][np.True_]``. That was misleading, as it behaved differently from 55 ``np.array([1, 2, 3])[np.True_]``. 56 57* Truth testing of an empty array is deprecated. To check if an array is not 58 empty, use ``array.size > 0``. 59 60* Calling ``np.bincount`` with ``minlength=None`` is deprecated. 61 ``minlength=0`` should be used instead. 62 63* Calling ``np.fromstring`` with the default value of the ``sep`` argument is 64 deprecated. When that argument is not provided, a broken version of 65 ``np.frombuffer`` is used that silently accepts unicode strings and -- after 66 encoding them as either utf-8 (python 3) or the default encoding 67 (python 2) -- treats them as binary data. If reading binary data is 68 desired, ``np.frombuffer`` should be used directly. 69 70* The ``style`` option of array2string is deprecated in non-legacy printing mode. 71 72* ``PyArray_SetUpdateIfCopyBase`` has been deprecated. For NumPy versions >= 1.14 73 use ``PyArray_SetWritebackIfCopyBase`` instead, see `C API changes` below for 74 more details. 75 76 77 78* The use of ``UPDATEIFCOPY`` arrays is deprecated, see `C API changes` below 79 for details. We will not be dropping support for those arrays, but they are 80 not compatible with PyPy. 81 82 83Future Changes 84============== 85 86* ``np.issubdtype`` will stop downcasting dtype-like arguments. 87 It might be expected that ``issubdtype(np.float32, 'float64')`` and 88 ``issubdtype(np.float32, np.float64)`` mean the same thing - however, there 89 was an undocumented special case that translated the former into 90 ``issubdtype(np.float32, np.floating)``, giving the surprising result of True. 91 92 This translation now gives a warning that explains what translation is 93 occurring. In the future, the translation will be disabled, and the first 94 example will be made equivalent to the second. 95 96* ``np.linalg.lstsq`` default for ``rcond`` will be changed. The ``rcond`` 97 parameter to ``np.linalg.lstsq`` will change its default to machine precision 98 times the largest of the input array dimensions. A FutureWarning is issued 99 when ``rcond`` is not passed explicitly. 100 101* ``a.flat.__array__()`` will return a writeable copy of ``a`` when ``a`` is 102 non-contiguous. Previously it returned an UPDATEIFCOPY array when ``a`` was 103 writeable. Currently it returns a non-writeable copy. See gh-7054 for a 104 discussion of the issue. 105 106* Unstructured void array's ``.item`` method will return a bytes object. In the 107 future, calling ``.item()`` on arrays or scalars of ``np.void`` datatype will 108 return a ``bytes`` object instead of a buffer or int array, the same as 109 returned by ``bytes(void_scalar)``. This may affect code which assumed the 110 return value was mutable, which will no longer be the case. A 111 ``FutureWarning`` is now issued when this would occur. 112 113 114Compatibility notes 115=================== 116 117The mask of a masked array view is also a view rather than a copy 118----------------------------------------------------------------- 119There was a FutureWarning about this change in NumPy 1.11.x. In short, it is 120now the case that, when changing a view of a masked array, changes to the mask 121are propagated to the original. That was not previously the case. This change 122affects slices in particular. Note that this does not yet work properly if the 123mask of the original array is ``nomask`` and the mask of the view is changed. 124See gh-5580 for an extended discussion. The original behavior of having a copy 125of the mask can be obtained by calling the ``unshare_mask`` method of the view. 126 127``np.ma.masked`` is no longer writeable 128--------------------------------------- 129Attempts to mutate the ``masked`` constant now error, as the underlying arrays 130are marked readonly. In the past, it was possible to get away with:: 131 132 # emulating a function that sometimes returns np.ma.masked 133 val = random.choice([np.ma.masked, 10]) 134 var_arr = np.asarray(val) 135 val_arr += 1 # now errors, previously changed np.ma.masked.data 136 137``np.ma`` functions producing ``fill_value`` s have changed 138----------------------------------------------------------- 139Previously, ``np.ma.default_fill_value`` would return a 0d array, but 140``np.ma.minimum_fill_value`` and ``np.ma.maximum_fill_value`` would return a 141tuple of the fields. Instead, all three methods return a structured ``np.void`` 142object, which is what you would already find in the ``.fill_value`` attribute. 143 144Additionally, the dtype guessing now matches that of ``np.array`` - so when 145passing a python scalar ``x``, ``maximum_fill_value(x)`` is always the same as 146``maximum_fill_value(np.array(x))``. Previously ``x = long(1)`` on Python 2 147violated this assumption. 148 149``a.flat.__array__()`` returns non-writeable arrays when ``a`` is non-contiguous 150-------------------------------------------------------------------------------- 151The intent is that the UPDATEIFCOPY array previously returned when ``a`` was 152non-contiguous will be replaced by a writeable copy in the future. This 153temporary measure is aimed to notify folks who expect the underlying array be 154modified in this situation that that will no longer be the case. The most 155likely places for this to be noticed is when expressions of the form 156``np.asarray(a.flat)`` are used, or when ``a.flat`` is passed as the out 157parameter to a ufunc. 158 159``np.tensordot`` now returns zero array when contracting over 0-length dimension 160-------------------------------------------------------------------------------- 161Previously ``np.tensordot`` raised a ValueError when contracting over 0-length 162dimension. Now it returns a zero array, which is consistent with the behaviour 163of ``np.dot`` and ``np.einsum``. 164 165``numpy.testing`` reorganized 166----------------------------- 167This is not expected to cause problems, but possibly something has been left 168out. If you experience an unexpected import problem using ``numpy.testing`` 169let us know. 170 171``np.asfarray`` no longer accepts non-dtypes through the ``dtype`` argument 172--------------------------------------------------------------------------- 173This previously would accept ``dtype=some_array``, with the implied semantics 174of ``dtype=some_array.dtype``. This was undocumented, unique across the numpy 175functions, and if used would likely correspond to a typo. 176 1771D ``np.linalg.norm`` preserves float input types, even for arbitrary orders 178---------------------------------------------------------------------------- 179Previously, this would promote to ``float64`` when arbitrary orders were 180passed, despite not doing so under the simple cases:: 181 182 >>> f32 = np.float32([[1, 2]]) 183 >>> np.linalg.norm(f32, 2.0, axis=-1).dtype 184 dtype('float32') 185 >>> np.linalg.norm(f32, 2.0001, axis=-1).dtype 186 dtype('float64') # numpy 1.13 187 dtype('float32') # numpy 1.14 188 189This change affects only ``float32`` and ``float16`` arrays. 190 191``count_nonzero(arr, axis=())`` now counts over no axes, not all axes 192--------------------------------------------------------------------- 193Elsewhere, ``axis==()`` is always understood as "no axes", but 194`count_nonzero` had a special case to treat this as "all axes". This was 195inconsistent and surprising. The correct way to count over all axes has always 196been to pass ``axis == None``. 197 198``__init__.py`` files added to test directories 199----------------------------------------------- 200This is for pytest compatibility in the case of duplicate test file names in 201the different directories. As a result, ``run_module_suite`` no longer works, 202i.e., ``python <path-to-test-file>`` results in an error. 203 204``.astype(bool)`` on unstructured void arrays now calls ``bool`` on each element 205-------------------------------------------------------------------------------- 206On Python 2, ``void_array.astype(bool)`` would always return an array of 207``True``, unless the dtype is ``V0``. On Python 3, this operation would usually 208crash. Going forwards, `astype` matches the behavior of ``bool(np.void)``, 209considering a buffer of all zeros as false, and anything else as true. 210Checks for ``V0`` can still be done with ``arr.dtype.itemsize == 0``. 211 212``MaskedArray.squeeze`` never returns ``np.ma.masked`` 213------------------------------------------------------ 214``np.squeeze`` is documented as returning a view, but the masked variant would 215sometimes return ``masked``, which is not a view. This has been fixed, so that 216the result is always a view on the original masked array. 217This breaks any code that used ``masked_arr.squeeze() is np.ma.masked``, but 218fixes code that writes to the result of `.squeeze()`. 219 220Renamed first parameter of ``can_cast`` from ``from`` to ``from_`` 221------------------------------------------------------------------ 222The previous parameter name ``from`` is a reserved keyword in Python, which made 223it difficult to pass the argument by name. This has been fixed by renaming 224the parameter to ``from_``. 225 226``isnat`` raises ``TypeError`` when passed wrong type 227------------------------------------------------------ 228The ufunc ``isnat`` used to raise a ``ValueError`` when it was not passed 229variables of type ``datetime`` or ``timedelta``. This has been changed to 230raising a ``TypeError``. 231 232``dtype.__getitem__`` raises ``TypeError`` when passed wrong type 233----------------------------------------------------------------- 234When indexed with a float, the dtype object used to raise ``ValueError``. 235 236User-defined types now need to implement ``__str__`` and ``__repr__`` 237--------------------------------------------------------------------- 238Previously, user-defined types could fall back to a default implementation of 239``__str__`` and ``__repr__`` implemented in numpy, but this has now been 240removed. Now user-defined types will fall back to the python default 241``object.__str__`` and ``object.__repr__``. 242 243Many changes to array printing, disableable with the new "legacy" printing mode 244------------------------------------------------------------------------------- 245The ``str`` and ``repr`` of ndarrays and numpy scalars have been changed in 246a variety of ways. These changes are likely to break downstream user's 247doctests. 248 249These new behaviors can be disabled to mostly reproduce numpy 1.13 behavior by 250enabling the new 1.13 "legacy" printing mode. This is enabled by calling 251``np.set_printoptions(legacy="1.13")``, or using the new ``legacy`` argument to 252``np.array2string``, as ``np.array2string(arr, legacy='1.13')``. 253 254In summary, the major changes are: 255 256* For floating-point types: 257 258 * The ``repr`` of float arrays often omits a space previously printed 259 in the sign position. See the new ``sign`` option to ``np.set_printoptions``. 260 * Floating-point arrays and scalars use a new algorithm for decimal 261 representations, giving the shortest unique representation. This will 262 usually shorten ``float16`` fractional output, and sometimes ``float32`` and 263 ``float128`` output. ``float64`` should be unaffected. See the new 264 ``floatmode`` option to ``np.set_printoptions``. 265 * Float arrays printed in scientific notation no longer use fixed-precision, 266 and now instead show the shortest unique representation. 267 * The ``str`` of floating-point scalars is no longer truncated in python2. 268 269* For other data types: 270 271 * Non-finite complex scalars print like ``nanj`` instead of ``nan*j``. 272 * ``NaT`` values in datetime arrays are now properly aligned. 273 * Arrays and scalars of ``np.void`` datatype are now printed using hex 274 notation. 275 276* For line-wrapping: 277 278 * The "dtype" part of ndarray reprs will now be printed on the next line 279 if there isn't space on the last line of array output. 280 * The ``linewidth`` format option is now always respected. 281 The `repr` or `str` of an array will never exceed this, unless a single 282 element is too wide. 283 * The last line of an array string will never have more elements than earlier 284 lines. 285 * An extra space is no longer inserted on the first line if the elements are 286 too wide. 287 288* For summarization (the use of ``...`` to shorten long arrays): 289 290 * A trailing comma is no longer inserted for ``str``. 291 Previously, ``str(np.arange(1001))`` gave 292 ``'[ 0 1 2 ..., 998 999 1000]'``, which has an extra comma. 293 * For arrays of 2-D and beyond, when ``...`` is printed on its own line in 294 order to summarize any but the last axis, newlines are now appended to that 295 line to match its leading newlines and a trailing space character is 296 removed. 297 298* ``MaskedArray`` arrays now separate printed elements with commas, always 299 print the dtype, and correctly wrap the elements of long arrays to multiple 300 lines. If there is more than 1 dimension, the array attributes are now 301 printed in a new "left-justified" printing style. 302* ``recarray`` arrays no longer print a trailing space before their dtype, and 303 wrap to the right number of columns. 304* 0d arrays no longer have their own idiosyncratic implementations of ``str`` 305 and ``repr``. The ``style`` argument to ``np.array2string`` is deprecated. 306* Arrays of ``bool`` datatype will omit the datatype in the ``repr``. 307* User-defined ``dtypes`` (subclasses of ``np.generic``) now need to 308 implement ``__str__`` and ``__repr__``. 309 310Some of these changes are described in more detail below. If you need to retain 311the previous behavior for doctests or other reasons, you may want to do 312something like:: 313 314 # FIXME: We need the str/repr formatting used in Numpy < 1.14. 315 try: 316 np.set_printoptions(legacy='1.13') 317 except TypeError: 318 pass 319 320 321C API changes 322============= 323 324PyPy compatible alternative to ``UPDATEIFCOPY`` arrays 325------------------------------------------------------ 326``UPDATEIFCOPY`` arrays are contiguous copies of existing arrays, possibly with 327different dimensions, whose contents are copied back to the original array when 328their refcount goes to zero and they are deallocated. Because PyPy does not use 329refcounts, they do not function correctly with PyPy. NumPy is in the process of 330eliminating their use internally and two new C-API functions, 331 332* ``PyArray_SetWritebackIfCopyBase`` 333* ``PyArray_ResolveWritebackIfCopy``, 334 335have been added together with a complimentary flag, 336``NPY_ARRAY_WRITEBACKIFCOPY``. Using the new functionality also requires that 337some flags be changed when new arrays are created, to wit: 338``NPY_ARRAY_INOUT_ARRAY`` should be replaced by ``NPY_ARRAY_INOUT_ARRAY2`` and 339``NPY_ARRAY_INOUT_FARRAY`` should be replaced by ``NPY_ARRAY_INOUT_FARRAY2``. 340Arrays created with these new flags will then have the ``WRITEBACKIFCOPY`` 341semantics. 342 343If PyPy compatibility is not a concern, these new functions can be ignored, 344although there will be a ``DeprecationWarning``. If you do wish to pursue PyPy 345compatibility, more information on these functions and their use may be found 346in the c-api_ documentation and the example in how-to-extend_. 347 348.. _c-api: https://github.com/numpy/numpy/blob/master/doc/source/reference/c-api.array.rst 349.. _how-to-extend: https://github.com/numpy/numpy/blob/master/doc/source/user/c-info.how-to-extend.rst 350 351 352New Features 353============ 354 355Encoding argument for text IO functions 356--------------------------------------- 357``genfromtxt``, ``loadtxt``, ``fromregex`` and ``savetxt`` can now handle files 358with arbitrary encoding supported by Python via the encoding argument. 359For backward compatibility the argument defaults to the special ``bytes`` value 360which continues to treat text as raw byte values and continues to pass latin1 361encoded bytes to custom converters. 362Using any other value (including ``None`` for system default) will switch the 363functions to real text IO so one receives unicode strings instead of bytes in 364the resulting arrays. 365 366External ``nose`` plugins are usable by ``numpy.testing.Tester`` 367---------------------------------------------------------------- 368``numpy.testing.Tester`` is now aware of ``nose`` plugins that are outside the 369``nose`` built-in ones. This allows using, for example, ``nose-timer`` like 370so: ``np.test(extra_argv=['--with-timer', '--timer-top-n', '20'])`` to 371obtain the runtime of the 20 slowest tests. An extra keyword ``timer`` was 372also added to ``Tester.test``, so ``np.test(timer=20)`` will also report the 20 373slowest tests. 374 375``parametrize`` decorator added to ``numpy.testing`` 376---------------------------------------------------- 377A basic ``parametrize`` decorator is now available in ``numpy.testing``. It is 378intended to allow rewriting yield based tests that have been deprecated in 379pytest so as to facilitate the transition to pytest in the future. The nose 380testing framework has not been supported for several years and looks like 381abandonware. 382 383The new ``parametrize`` decorator does not have the full functionality of the 384one in pytest. It doesn't work for classes, doesn't support nesting, and does 385not substitute variable names. Even so, it should be adequate to rewrite the 386NumPy tests. 387 388``chebinterpolate`` function added to ``numpy.polynomial.chebyshev`` 389-------------------------------------------------------------------- 390The new ``chebinterpolate`` function interpolates a given function at the 391Chebyshev points of the first kind. A new ``Chebyshev.interpolate`` class 392method adds support for interpolation over arbitrary intervals using the scaled 393and shifted Chebyshev points of the first kind. 394 395Support for reading lzma compressed text files in Python 3 396---------------------------------------------------------- 397With Python versions containing the ``lzma`` module the text IO functions can 398now transparently read from files with ``xz`` or ``lzma`` extension. 399 400``sign`` option added to ``np.setprintoptions`` and ``np.array2string`` 401----------------------------------------------------------------------- 402This option controls printing of the sign of floating-point types, and may be 403one of the characters '-', '+' or ' '. With '+' numpy always prints the sign of 404positive values, with ' ' it always prints a space (whitespace character) in 405the sign position of positive values, and with '-' it will omit the sign 406character for positive values. The new default is '-'. 407 408This new default changes the float output relative to numpy 1.13. The old 409behavior can be obtained in 1.13 "legacy" printing mode, see compatibility 410notes above. 411 412``hermitian`` option added to``np.linalg.matrix_rank`` 413------------------------------------------------------ 414The new ``hermitian`` option allows choosing between standard SVD based matrix 415rank calculation and the more efficient eigenvalue based method for 416symmetric/hermitian matrices. 417 418``threshold`` and ``edgeitems`` options added to ``np.array2string`` 419-------------------------------------------------------------------- 420These options could previously be controlled using ``np.set_printoptions``, but 421now can be changed on a per-call basis as arguments to ``np.array2string``. 422 423``concatenate`` and ``stack`` gained an ``out`` argument 424-------------------------------------------------------- 425A preallocated buffer of the desired dtype can now be used for the output of 426these functions. 427 428Support for PGI flang compiler on Windows 429----------------------------------------- 430The PGI flang compiler is a Fortran front end for LLVM released by NVIDIA under 431the Apache 2 license. It can be invoked by :: 432 433 python setup.py config --compiler=clang --fcompiler=flang install 434 435There is little experience with this new compiler, so any feedback from people 436using it will be appreciated. 437 438 439Improvements 440============ 441 442Numerator degrees of freedom in ``random.noncentral_f`` need only be positive. 443------------------------------------------------------------------------------ 444Prior to NumPy 1.14.0, the numerator degrees of freedom needed to be > 1, but 445the distribution is valid for values > 0, which is the new requirement. 446 447The GIL is released for all ``np.einsum`` variations 448---------------------------------------------------- 449Some specific loop structures which have an accelerated loop version 450did not release the GIL prior to NumPy 1.14.0. This oversight has been 451fixed. 452 453The `np.einsum` function will use BLAS when possible and optimize by default 454---------------------------------------------------------------------------- 455The ``np.einsum`` function will now call ``np.tensordot`` when appropriate. 456Because ``np.tensordot`` uses BLAS when possible, that will speed up execution. 457By default, ``np.einsum`` will also attempt optimization as the overhead is 458small relative to the potential improvement in speed. 459 460``f2py`` now handles arrays of dimension 0 461------------------------------------------ 462``f2py`` now allows for the allocation of arrays of dimension 0. This allows 463for more consistent handling of corner cases downstream. 464 465``numpy.distutils`` supports using MSVC and mingw64-gfortran together 466--------------------------------------------------------------------- 467Numpy distutils now supports using Mingw64 gfortran and MSVC compilers 468together. This enables the production of Python extension modules on Windows 469containing Fortran code while retaining compatibility with the 470binaries distributed by Python.org. Not all use cases are supported, 471but most common ways to wrap Fortran for Python are functional. 472 473Compilation in this mode is usually enabled automatically, and can be 474selected via the ``--fcompiler`` and ``--compiler`` options to 475``setup.py``. Moreover, linking Fortran codes to static OpenBLAS is 476supported; by default a gfortran compatible static archive 477``openblas.a`` is looked for. 478 479``np.linalg.pinv`` now works on stacked matrices 480------------------------------------------------ 481Previously it was limited to a single 2d array. 482 483``numpy.save`` aligns data to 64 bytes instead of 16 484---------------------------------------------------- 485Saving NumPy arrays in the ``npy`` format with ``numpy.save`` inserts 486padding before the array data to align it at 64 bytes. Previously 487this was only 16 bytes (and sometimes less due to a bug in the code 488for version 2). Now the alignment is 64 bytes, which matches the 489widest SIMD instruction set commonly available, and is also the most 490common cache line size. This makes ``npy`` files easier to use in 491programs which open them with ``mmap``, especially on Linux where an 492``mmap`` offset must be a multiple of the page size. 493 494NPZ files now can be written without using temporary files 495---------------------------------------------------------- 496In Python 3.6+ ``numpy.savez`` and ``numpy.savez_compressed`` now write 497directly to a ZIP file, without creating intermediate temporary files. 498 499Better support for empty structured and string types 500---------------------------------------------------- 501Structured types can contain zero fields, and string dtypes can contain zero 502characters. Zero-length strings still cannot be created directly, and must be 503constructed through structured dtypes:: 504 505 str0 = np.empty(10, np.dtype([('v', str, N)]))['v'] 506 void0 = np.empty(10, np.void) 507 508It was always possible to work with these, but the following operations are 509now supported for these arrays: 510 511 * `arr.sort()` 512 * `arr.view(bytes)` 513 * `arr.resize(...)` 514 * `pickle.dumps(arr)` 515 516Support for ``decimal.Decimal`` in ``np.lib.financial`` 517------------------------------------------------------- 518Unless otherwise stated all functions within the ``financial`` package now 519support using the ``decimal.Decimal`` built-in type. 520 521Float printing now uses "dragon4" algorithm for shortest decimal representation 522------------------------------------------------------------------------------- 523The ``str`` and ``repr`` of floating-point values (16, 32, 64 and 128 bit) are 524now printed to give the shortest decimal representation which uniquely 525identifies the value from others of the same type. Previously this was only 526true for ``float64`` values. The remaining float types will now often be shorter 527than in numpy 1.13. Arrays printed in scientific notation now also use the 528shortest scientific representation, instead of fixed precision as before. 529 530 Additionally, the `str` of float scalars scalars will no longer be truncated 531 in python2, unlike python2 `float`s. `np.double` scalars now have a ``str`` 532 and ``repr`` identical to that of a python3 float. 533 534New functions ``np.format_float_scientific`` and ``np.format_float_positional`` 535are provided to generate these decimal representations. 536 537A new option ``floatmode`` has been added to ``np.set_printoptions`` and 538``np.array2string``, which gives control over uniqueness and rounding of 539printed elements in an array. The new default is ``floatmode='maxprec'`` with 540``precision=8``, which will print at most 8 fractional digits, or fewer if an 541element can be uniquely represented with fewer. A useful new mode is 542``floatmode="unique"``, which will output enough digits to specify the array 543elements uniquely. 544 545Numpy complex-floating-scalars with values like ``inf*j`` or ``nan*j`` now 546print as ``infj`` and ``nanj``, like the pure-python ``complex`` type. 547 548The ``FloatFormat`` and ``LongFloatFormat`` classes are deprecated and should 549both be replaced by ``FloatingFormat``. Similarly ``ComplexFormat`` and 550``LongComplexFormat`` should be replaced by ``ComplexFloatingFormat``. 551 552``void`` datatype elements are now printed in hex notation 553---------------------------------------------------------- 554A hex representation compatible with the python ``bytes`` type is now printed 555for unstructured ``np.void`` elements, e.g., ``V4`` datatype. Previously, in 556python2 the raw void data of the element was printed to stdout, or in python3 557the integer byte values were shown. 558 559printing style for ``void`` datatypes is now independently customizable 560----------------------------------------------------------------------- 561The printing style of ``np.void`` arrays is now independently customizable 562using the ``formatter`` argument to ``np.set_printoptions``, using the 563``'void'`` key, instead of the catch-all ``numpystr`` key as before. 564 565Reduced memory usage of ``np.loadtxt`` 566-------------------------------------- 567``np.loadtxt`` now reads files in chunks instead of all at once which decreases 568its memory usage significantly for large files. 569 570 571Changes 572======= 573 574Multiple-field indexing/assignment of structured arrays 575------------------------------------------------------- 576The indexing and assignment of structured arrays with multiple fields has 577changed in a number of ways, as warned about in previous releases. 578 579First, indexing a structured array with multiple fields, e.g., 580``arr[['f1', 'f3']]``, returns a view into the original array instead of a 581copy. The returned view will have extra padding bytes corresponding to 582intervening fields in the original array, unlike the copy in 1.13, which will 583affect code such as ``arr[['f1', 'f3']].view(newdtype)``. 584 585Second, assignment between structured arrays will now occur "by position" 586instead of "by field name". The Nth field of the destination will be set to the 587Nth field of the source regardless of field name, unlike in numpy versions 1.6 588to 1.13 in which fields in the destination array were set to the 589identically-named field in the source array or to 0 if the source did not have 590a field. 591 592Correspondingly, the order of fields in a structured dtypes now matters when 593computing dtype equality. For example, with the dtypes :: 594 595 x = dtype({'names': ['A', 'B'], 'formats': ['i4', 'f4'], 'offsets': [0, 4]}) 596 y = dtype({'names': ['B', 'A'], 'formats': ['f4', 'i4'], 'offsets': [4, 0]}) 597 598the expression ``x == y`` will now return ``False``, unlike before. 599This makes dictionary based dtype specifications like 600``dtype({'a': ('i4', 0), 'b': ('f4', 4)})`` dangerous in python < 3.6 601since dict key order is not preserved in those versions. 602 603Assignment from a structured array to a boolean array now raises a ValueError, 604unlike in 1.13, where it always set the destination elements to ``True``. 605 606Assignment from structured array with more than one field to a non-structured 607array now raises a ValueError. In 1.13 this copied just the first field of the 608source to the destination. 609 610Using field "titles" in multiple-field indexing is now disallowed, as is 611repeating a field name in a multiple-field index. 612 613The documentation for structured arrays in the user guide has been 614significantly updated to reflect these changes. 615 616Integer and Void scalars are now unaffected by ``np.set_string_function`` 617------------------------------------------------------------------------- 618Previously, unlike most other numpy scalars, the ``str`` and ``repr`` of 619integer and void scalars could be controlled by ``np.set_string_function``. 620This is no longer possible. 621 6220d array printing changed, ``style`` arg of array2string deprecated 623------------------------------------------------------------------- 624Previously the ``str`` and ``repr`` of 0d arrays had idiosyncratic 625implementations which returned ``str(a.item())`` and ``'array(' + 626repr(a.item()) + ')'`` respectively for 0d array ``a``, unlike both numpy 627scalars and higher dimension ndarrays. 628 629Now, the ``str`` of a 0d array acts like a numpy scalar using ``str(a[()])`` 630and the ``repr`` acts like higher dimension arrays using ``formatter(a[()])``, 631where ``formatter`` can be specified using ``np.set_printoptions``. The 632``style`` argument of ``np.array2string`` is deprecated. 633 634This new behavior is disabled in 1.13 legacy printing mode, see compatibility 635notes above. 636 637Seeding ``RandomState`` using an array requires a 1-d array 638----------------------------------------------------------- 639``RandomState`` previously would accept empty arrays or arrays with 2 or more 640dimensions, which resulted in either a failure to seed (empty arrays) or for 641some of the passed values to be ignored when setting the seed. 642 643``MaskedArray`` objects show a more useful ``repr`` 644--------------------------------------------------- 645The ``repr`` of a ``MaskedArray`` is now closer to the python code that would 646produce it, with arrays now being shown with commas and dtypes. Like the other 647formatting changes, this can be disabled with the 1.13 legacy printing mode in 648order to help transition doctests. 649 650The ``repr`` of ``np.polynomial`` classes is more explicit 651---------------------------------------------------------- 652It now shows the domain and window parameters as keyword arguments to make 653them more clear:: 654 655 >>> np.polynomial.Polynomial(range(4)) 656 Polynomial([0., 1., 2., 3.], domain=[-1, 1], window=[-1, 1]) 657