Skip to content

Instantly share code, notes, and snippets.

@ganesh-k13
Last active February 4, 2021 17:05
Show Gist options
  • Save ganesh-k13/6201227c5d3d65902c6eaf71357e72b1 to your computer and use it in GitHub Desktop.
Save ganesh-k13/6201227c5d3d65902c6eaf71357e72b1 to your computer and use it in GitHub Desktop.
Numpy snippetes
import numpy as np
c16 = np.complex128()
f16 = np.float128()
f8 = np.float64()
i8 = np.int64()
u8 = np.uint64()
c8 = np.complex64()
f4 = np.float32()
i4 = np.int32()
u4 = np.uint32()
dt = np.datetime64(0, "D")
td = np.timedelta64(0, "D")
b_ = np.bool_()
b = bool()
c = complex()
f = float()
i = int()
AR = np.array([0], dtype=np.int64)
AR.setflags(write=False)
SEQ = (0, 1, 2, 3, 4)
# Time structures
dt > dt
td > td
td > i
td > i4
td > i8
td > AR
td > SEQ
# boolean
b_ > b
b_ > b_
b_ > i
b_ > i8
b_ > i4
b_ > u8
b_ > u4
b_ > f
b_ > f16
b_ > f8
b_ > f4
b_ > c
b_ > c16
b_ > c8
b_ > AR
b_ > SEQ
# Complex
c16 > c16
c16 > f16
c16 > f8
c16 > i8
c16 > c8
c16 > f4
c16 > i4
c16 > b_
c16 > b
c16 > c
c16 > f
c16 > i
c16 > AR
c16 > SEQ
c16 > c16
f16 > c16
f8 > c16
i8 > c16
c8 > c16
f4 > c16
i4 > c16
b_ > c16
b > c16
c > c16
f > c16
i > c16
AR > c16
SEQ > c16
c8 > c16
c8 > f16
c8 > f8
c8 > i8
c8 > c8
c8 > f4
c8 > i4
c8 > b_
c8 > b
c8 > c
c8 > f
c8 > i
c8 > AR
c8 > SEQ
c16 > c8
f16 > c8
f8 > c8
i8 > c8
c8 > c8
f4 > c8
i4 > c8
b_ > c8
b > c8
c > c8
f > c8
i > c8
AR > c8
SEQ > c8
# Float
f16 > f8
f16 > i8
f16 > f4
f16 > i4
f16 > b_ # Crash
f16 > b
f16 > c
f16 > f
f16 > i
f16 > AR
f16 > f8
i8 > f16
f4 > f16
i4 > f16
b_ > f16
b > f16
c > f16
f > f16
i > f16
AR > f16
f8 > f8
f8 > i8
f8 > f4
f8 > i4
f8 > b_
f8 > b
f8 > c
f8 > f
f8 > i
f8 > AR
f8 > SEQ
f8 > f8
i8 > f8
f4 > f8
i4 > f8
b_ > f8
b > f8
c > f8
f > f8
i > f8
AR > f8
SEQ > f8
f4 > f16
f4 > f8
f4 > i8
f4 > f4
f4 > i4
f4 > b_
f4 > b
f4 > c
f4 > f
f4 > i
f4 > AR
f4 > SEQ
f16 > f4
f8 > f4
i8 > f4
f4 > f4
i4 > f4
b_ > f4
b > f4
c > f4
f > f4
i > f4
AR > f4
SEQ > f4
# Int
i8 > i8
i8 > u8
i8 > i4
i8 > u4
i8 > b_
i8 > b
i8 > c
i8 > f
i8 > i
i8 > AR
i8 > SEQ
u8 > u8
u8 > i4
u8 > u4
u8 > b_
u8 > b
u8 > c
u8 > f
u8 > i
u8 > AR
u8 > SEQ
i8 > i8
u8 > i8
i4 > i8
u4 > i8
b_ > i8
b > i8
c > i8
f > i8
i > i8
AR > i8
SEQ > i8
u8 > u8
i4 > u8
u4 > u8
b_ > u8
b > u8
c > u8
f > u8
i > u8
AR > u8
SEQ > u8
i4 > i8
i4 > i4
i4 > i
i4 > b_
i4 > b
i4 > AR
i4 > SEQ
u4 > i8
u4 > i4
u4 > u8
u4 > u4
u4 > i
u4 > b_
u4 > b
u4 > AR
u4 > SEQ
i8 > i4
i4 > i4
i > i4
b_ > i4
b > i4
AR > i4
SEQ > i4
i8 > u4
i4 > u4
u8 > u4
u4 > u4
b_ > u4
b > u4
i > u4
AR > u4
SEQ > u4
import numpy as np
import sys
import argparse
import cProfile
import os
import pathlib
print(np.__version__)
def divide(x, d):
x//d
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-s', '--size', action='store', type=int, help='Size of array')
parser.add_argument('-d', '--divisor', action='store', type=int, help='Divisor')
parser.add_argument('-f', '--folder', action='store', help='Profiler output folder')
options = parser.parse_args()
pathlib.Path(options.folder,).mkdir(parents=True, exist_ok=True)
for i in ((10**p1) for p1 in range(2, options.size)):
for j in ((i//10)*p2 for p2 in range(1, 10)):
print(f"{j}...")
x = np.arange(j)
cProfile.run(f'divide(x, options.divisor)', f'{options.folder}/div_{j}')
# Graph for: python3 large_profiler.py -s 10 -d 30
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment