@@ -193,19 +193,53 @@ raising a ``TypeError``.
193
193
-----------------------------------------------------------------
194
194
When indexed with a float, the dtype object used to raise ``ValueError ``.
195
195
196
- Changes to array printing, and the new "legacy" printing mode.
197
- --------------------------------------------------------------
198
- The new ``sign='-' `` option (see new features below) causes the ``repr `` of
199
- float arrays to often omit a whitespace previously printed in the sign
200
- position, and 0d arrays also now print with small whitespace and precision
201
- differences (see changes below). These changes are likely to break downstream
202
- user's doctests.
196
+ Many changes to array printing, disableable with the new "legacy" printing mode
197
+ -------------------------------------------------------------------------------
198
+ The ``str `` and ``repr `` of ndarrays and numpy scalars have been changed in
199
+ a variety of ways. These changes are likely to break downstream user's
200
+ doctests.
203
201
204
202
These new behaviors can be disabled to mostly reproduce numpy 1.13 behavior by
205
203
enabling the new 1.13 "legacy" printing mode. This is enabled by calling
206
204
``np.set_printoptions(legacy="1.13") ``, or using the new ``legacy `` argument to
207
205
``np.array2string ``, as ``np.array2string(arr, legacy='1.13') ``.
208
206
207
+ In summary, the major changes are:
208
+
209
+ * The ``repr `` of float arrays often omits a whitespace previously printed
210
+ in the sign position. See the new ``sign `` option to ``np.set_printoptions ``.
211
+ * Floating-point arrays and scalars use a new algorithm for decimal
212
+ representations, giving the shortest unique representation. This will
213
+ usually shorten ``float16 `` fractional output, and sometimes ``float32 `` and
214
+ ``float128 `` output. ``float64 `` should be unaffected. See the new
215
+ ``floatmode `` option to ``np.set_printoptions ``.
216
+ * Float arrays printed in scientific notation no longer use fixed-precision,
217
+ and now instead show the shortest unique representation.
218
+ * The ``str `` of floating-point scalars is no longer truncated in python2.
219
+ * Non-finite complex scalars print like ``nanj `` instead of ``nan*j ``.
220
+ * ``MaskedArray `` arrays now separate printed elements with commas, always
221
+ print the dtype, and correctly wrap the elements of long arrays to multiple
222
+ lines. If there is more than 1 dimension, the array attributes are now
223
+ printed in a new "left-justified" printing style.
224
+ * ``NaT `` values in datetime arrays are now properly aligned.
225
+ * Arrays and scalars of ``np.void `` datatype are now print using hex notation.
226
+ * 0d arrays no longer have their own idiosyncratic implementations of ``str ``
227
+ and ``repr ``. The ``style `` argument to ``np.array2string `` is deprecated.
228
+ * Arrays of ``bool `` datatype will omit the datatype in the ``repr ``.
229
+ * The "dtype" part of ndarray reprs will now be printed on the next line
230
+ if there isn't space on the last line of array output.
231
+ * User-defined ``dtypes `` (subclasses of ``np.generic ``) now need to
232
+ implement ``__str__ `` and ``__repr__ ``.
233
+ * The ``... `` used to summarize long arrays now omits a trailing comma for
234
+ ``str ``. Previously, ``str(np.arange(1001)) `` gave
235
+ ``'[ 0 1 2 ..., 998 999 1000]' ``, which has an extra comma.
236
+ * When a summarization ``... `` would be printed on its own line, eg for
237
+ summarization along any ndarray dimension but the last, a trailing
238
+ whitespace is now removed and trailing newlines added to match
239
+ the leading newlines.
240
+
241
+ Some of these changes are described in more detail below.
242
+
209
243
210
244
C API changes
211
245
=============
@@ -290,6 +324,7 @@ The new ``chebinterpolate`` function interpolates a given function at the
290
324
Chebyshev points of the first kind. A new ``Chebyshev.interpolate `` class
291
325
method adds support for interpolation over arbitrary intervals using the scaled
292
326
and shifted Chebyshev points of the first kind.
327
+
293
328
Support for reading lzma compressed text files in Python 3
294
329
----------------------------------------------------------
295
330
With Python versions containing the ``lzma `` module the text IO functions can
@@ -405,19 +440,20 @@ support using the ``decimal.Decimal`` built-in type.
405
440
406
441
Float printing now uses "dragon4" algorithm for shortest decimal representation
407
442
-------------------------------------------------------------------------------
408
- All numpy floating-point types (16, 32, 64 and 128 bit) can now be printed to
409
- give shortest decimal representation of the number which uniquely identifies
410
- the value from others of the same type.
443
+ The ``str `` and ``repr `` of floating-point values (16, 32, 64 and 128 bit) are
444
+ now printed to give the shortest decimal representation which uniquely
445
+ identifies the value from others of the same type. Previously this was only
446
+ true for ``float64 `` values. The remaining float types will now often be shorter
447
+ than in numpy 1.13. Arrays printed in scientific notation now also use the
448
+ shortest scientific representation, instead of fixed precision as before.
449
+
450
+ Additionally, the `str ` of float scalars scalars will no longer be truncated
451
+ in python2, unlike python2 `float`s. `np.double ` scalars now have a ``str ``
452
+ and ``repr `` identical to that of a python3 float.
411
453
412
454
New functions ``np.format_float_scientific `` and ``np.format_float_positional ``
413
455
are provided to generate these decimal representations.
414
456
415
- The ``str `` and ``repr `` of floating-point scalars now use the shortest unique
416
- decimal representation. This means float128s will appear longer and float16s
417
- shorter than in numpy 1.13. Additionally, the `str ` of these scalars will no
418
- longer be truncated in python2, unlike python2 `float`s. `np.double ` scalars
419
- now have a `str ` and `repr ` identical to that of a python3 float.
420
-
421
457
A new option ``floatmode `` has been added to ``np.set_printoptions `` and
422
458
``np.array2string ``, which gives control over uniqueness and rounding of
423
459
printed elements in an array. The new default is ``floatmode='maxprec' `` with
@@ -445,6 +481,7 @@ printing style for ``void`` datatypes is now independently customizable
445
481
The printing style of ``np.void `` arrays is now independently customizable
446
482
using the ``formatter `` argument to ``np.set_printoptions ``, using the
447
483
``'void' `` key, instead of the catch-all ``numpystr `` key as before.
484
+
448
485
Reduced memory usage of ``np.loadtxt ``
449
486
--------------------------------------
450
487
``np.loadtxt `` now reads files in chunks instead of all at once which decreases
@@ -495,6 +532,9 @@ source to the destination.
495
532
Using field "titles" in multiple-field indexing is now disallowed, as is
496
533
repeating a field name in a multiple-field index.
497
534
535
+ The documentation for structured arrays in the user guide has been
536
+ significantly updated to reflect these changes.
537
+
498
538
User-defined types now need to implement ``__str__ `` and ``__repr__ ``
499
539
---------------------------------------------------------------------
500
540
Previously, user-defined types could fall back to a default implementation of
0 commit comments