Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6bfc36c

Browse filesBrowse files
sebergmattip
andauthored
Apply suggestions from code review
Co-authored-by: Matti Picus <matti.picus@gmail.com>
1 parent c7aaddb commit 6bfc36c
Copy full SHA for 6bfc36c

File tree

2 files changed

+6
-3
lines changed
Filter options

2 files changed

+6
-3
lines changed
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
Use f-strings to choose printing options for numeric dtypes
22
-----------------------------------------------------------
33

4-
You can use f-strings now to format the precision, sign and the use of exponential notation for numeric arrays with a syntax inspired from [Python Format Specification Mini-Language](https://docs.python.org/3/library/string.html#formatspec).
4+
You can now use f-strings to format the precision, sign and the use of
5+
exponential notation for numeric arrays with a syntax inspired by
6+
:ref:py:`Python Format Specification Mini-Language <formatspec>`.
57

68
>>> a = np.array([1.001, -0.101, np.pi, -np.e])
79
>>> print(f"{a:.2f}")
810
[ 1. -0.1 3.14 -2.72]
911
>>> print(f"{a:+.2e}")
1012
[+1.00e+00 -1.01e-01 +3.14e+00 -2.72e+00]
1113

12-
See ``_parse_format_spec`` and ``array2string`` for reference.
14+
See `numpy.array2string` for reference.

‎numpy/core/src/multiarray/strfuncs.c

Copy file name to clipboardExpand all lines: numpy/core/src/multiarray/strfuncs.c
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,10 @@ array_format(PyArrayObject *self, PyObject *args)
116116
}
117117

118118
/* if len(format_spec) == 0 this function is equivalent to __str__ */
119-
if (PyUnicode_GET_LENGTH(format_spec) == 0)
119+
if (PyUnicode_GET_LENGTH(format_spec) == 0) {
120120
// use the builtin
121121
return PyObject_Str((PyObject *)self);
122+
}
122123

123124
/* nd arrays - forward to _default_array_format */
124125
// ndim > 0

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.