forked from Qwertyssp/python_ebook
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumericaltypes.py
More file actions
48 lines (38 loc) · 820 Bytes
/
numericaltypes.py
File metadata and controls
48 lines (38 loc) · 820 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import numpy as np
# Chapter 2 Beginning with NumPy fundamentals
#
# Demonstrates the NumPy numerical types
# and conversion between them.
#
# Run from the commandline with
#
# python numericaltypes.py
print "In: float64(42)"
print np.float64(42)
#Out: 42.0
print "In: int8(42.0)"
print np.int8(42.0)
#Out: 42
print "In: bool(42)"
print np.bool(42)
#Out: True
print np.bool(0)
print "In: bool(42.0)"
print np.bool(42.0)
#Out: True
print "In: float(True)"
print np.float(True)
#Out: 1.0
print np.float(False)
print "In: arange(7, dtype=uint16)"
print np.arange(7, dtype=np.uint16)
#Out: array([0, 1, 2, 3, 4, 5, 6], dtype=uint16)
print "In: int(42.0 + 1.j)"
try:
print np.int(42.0 + 1.j)
except TypeError:
print "TypeError"
#Type error
print "In: float(42.0 + 1.j)"
print float(42.0 + 1.j)
#Type error