Created
June 19, 2020 17:19
-
-
Save michaelchughes/96af54089de84d674720f09f8e494c01 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vals_float32 = np.logspace(0, 5, dtype=np.float32) | |
vals_float64 = np.logspace(0, 5, dtype=np.float64) | |
## Pretty-print output of array so each float takes same num chars | |
def pprint_arr(arr, n_per_line=6): | |
for s in range(0, arr.size, n_per_line): | |
chunk = arr[s:s+n_per_line] | |
print(" ".join(["%10s" % np.format_float_scientific(x, precision=2, unique=False, exp_digits=3) for x in chunk])) | |
print() | |
print("=================== with 32-bit floats") | |
## Grid of possible inputs | |
pprint_arr(vals_float32) | |
pprint_arr(np.exp(vals_float32)) | |
print() | |
print("=================== with 64-bit floats") | |
## Grid of possible inputs | |
pprint_arr(vals_float64) | |
pprint_arr(np.exp(vals_float64)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Expected Output