Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit245bee9

Browse files
committed
DOC:__trunc__ for scalars (#27789)
1 parent4bdc3ba commit245bee9

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Add __trunc__ method to NumPy scalar types
2+
==========================================
3+
4+
NumPy scalar floating and integer types now implement the ``__trunc__`` special method, matching Python’s built-in numeric types. This enables direct use of:func:`math.trunc` and the ``__trunc__`` dunder method on NumPy scalars:
5+
6+
Examples
7+
--------
8+
9+
..code-block::python
10+
11+
>>>import numpyas np
12+
>>>import math
13+
>>> math.trunc(np.float16(np.pi))
14+
3
15+
>>> np.float16(-np.pi).__trunc__()
16+
-3
17+
>>> np.int32(42).__trunc__()
18+
42
19+
20+
Attempting to truncate infinite or NaN values for floating point types will now raise the same errors as Python floats.
21+
22+
..versionadded::2.3

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp