8000 Merge pull request #14558 from WarrenWeckesser/update-doc-code · numpy/numpy@4ff3af3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4ff3af3

Browse files
authored
Merge pull request #14558 from WarrenWeckesser/update-doc-code
DOC: Fix code that generates the table in the 'Casting Rules' section.
2 parents 61289fb + e4bc314 commit 4ff3af3

File tree

1 file changed

+35
-33
lines changed

1 file changed

+35
-33
lines changed

doc/source/reference/ufuncs.rst

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -228,45 +228,47 @@ can generate this table for your system with the code given in the Figure.
228228

229229
.. admonition:: Figure
230230

231-
Code segment showing the "can cast safely" table for a 32-bit system.
231+
Code segment showing the "can cast safely" table for a 64-bit system.
232+
Generally the output depends on the system; your system might result in
233+
a different table.
232234

235+
>>> mark = {False: ' -', True: ''}
233236
>>> def print_table(ntypes):
234-
... print 'X',
235-
... for char in ntypes: print char,
236-
... print
237+
... print('X ' + ' '.join(ntypes))
237238
... for row in ntypes:
238-
... print row,
239+
... print(row, end='')
239240
... for col in ntypes:
240-
... print int(np.can_cast(row, col)),
241-
... print
241+
... print(mark[np.can_cast(row, col)], end='')
242+
... print()
243+
...
242244
>>> print_table(np.typecodes['All'])
243245
X ? b h i l q p B H I L Q P e f d g F D G S U V O M m
244-
? 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
245-
b 0 1 1 1 1 1 1 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0
246-
h 0 0 1 1 1 1 1 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 0 0
247-
i 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 1 1 0 1 1 1 1 1 1 0 0
248-
l 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 1 1 0 1 1 1 1 1 1 0 0
249-
q 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 1 1 0 1 1 1 1 1 1 0 0
250-
p 0 0 0 0 1 1 1 0 0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0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0
269-
m 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
246+
? ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ - ✓
247+
b - ✓ ✓ ✓ ✓ ✓ ✓ - - - - - - ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ - ✓
248+
h - - ✓ ✓ ✓ ✓ ✓ - - - - - - - ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ - ✓
249+
i - - - ✓ ✓ ✓ ✓ - - - - - - - - ✓ ✓ - ✓ ✓ ✓ ✓ ✓ ✓ - ✓
250+
l - - - - ✓ ✓ ✓ - - - - - - - - ✓ ✓ - ✓ ✓ ✓ ✓ ✓ ✓ - ✓
251+
q - - - - ✓ ✓ ✓ - - - - - - - - ✓ ✓ - ✓ ✓ ✓ ✓ ✓ ✓ - ✓
252+
p - - - - ✓ ✓ ✓ - - - - - - - - ✓ ✓ - ✓ ✓ ✓ ✓ ✓ ✓ - ✓
253+
B - - ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ - ✓
254+
H - - - ✓ ✓ ✓ ✓ - ✓ ✓ ✓ ✓ ✓ - ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ - ✓
255+
I - - - - ✓ ✓ ✓ - - ✓ ✓ ✓ ✓ - - ✓ ✓ - ✓ ✓ ✓ ✓ ✓ ✓ - ✓
256+
L - - - - - - - - - - ✓ ✓ ✓ - - ✓ ✓ - ✓ ✓ ✓ ✓ ✓ ✓ - ✓
257+
Q - - - - - - - - - - ✓ ✓ ✓ - - ✓ ✓ - ✓ ✓ ✓ ✓ ✓ ✓ - ✓
258+
P - - - - - - - - - - ✓ ✓ ✓ - - ✓ ✓ - ✓ ✓ ✓ ✓ ✓ ✓ - ✓
259+
e - - - - - - - - - - - - - ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ - -
260+
f - - - - - - - - - - - - - - ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ - -
261+
d - - - - - - - - - - - - - - - ✓ ✓ - ✓ ✓ ✓ ✓ ✓ ✓ - -
262+
g - - - - - - - - - - - - - - - - ✓ - - ✓ ✓ ✓ ✓ ✓ - -
263+
F - - - - - - - - - - - - - - - - - ✓ ✓ ✓ ✓ ✓ ✓ ✓ - -
264+
D - - - - - - - - - - - - - - - - - - ✓ ✓ ✓ ✓ ✓ ✓ - -
265+
G - - - - - - - - - - - - - - - - - - - ✓ ✓ ✓ ✓ ✓ - -
266+
S - - - - - - - - - - - - - - - - - - - - ✓ ✓ ✓ ✓ - -
267+
U - - - - - - - - - - - - - - - - - - - - - ✓ ✓ ✓ - -
268+
V - - - - - - - - - - - - - - - - - - - - - - ✓ ✓ - -
269+
O - - - - - - - - - - - - - - - - - - - - - - ✓ ✓ - -
270+
M - - - - - - - - - - - - - - - - - - - - - - ✓ ✓ ✓ -
271+
m - - - - - - - - - - - - - - - - - - - - - - ✓ ✓ - ✓
270272

271273

272274
You should note that, while included in the table for completeness,

0 commit comments

Comments
 (0)
0