DEV Community

Cover image for Previewing a .npy file
Talles L
Talles L

Posted on

Previewing a .npy file

Here's a little script I made to preview some of my (huge) NumPy's .npy files:

#! /usr/bin/env python3

from sys import argv, getsizeof
from numpy import load

data = load(argv[1])

size = getsizeof(data)
size_kb = size / 1024
size_mb = size / (1024 ** 2)

print(f'Shape: {data.shape}')
print(f'Data type: {data.dtype}')
print(f'Size: {data.size}')
print(f'Occupied RAM: {size} bytes ({size_kb:.2f} KB, {size_mb:.2f} MB)')
print()
print('Content preview:')
print(data[:200])
print()
Enter fullscreen mode Exit fullscreen mode

Output example:

Shape: (7468541, 1024)
Data type: float64
Size: 7647785984
Occupied RAM: 61182288000 bytes (59748328.12 KB, 58347.98 MB)

Content preview:
[[-0.07646164 -0.1739306  -0.5888805  ...  0.01423606 -0.9392316
   0.09138256]
 [-0.11803283 -0.27169943 -0.6343062  ... -0.09977917 -1.1889461
   0.4786728 ]
 [ 0.33316666 -0.25544062 -0.06951106 ...  0.21167792 -0.5084344
   0.18797423]
 ...
 [-0.5917888  -0.24519566  0.0250344  ...  0.10975855 -0.77993053
  -0.19755107]
 [-0.07159433 -0.3512457  -0.23779947 ...  0.32987532 -0.7357785
   0.2488086 ]
 [ 0.01552454 -0.5029288  -0.08170918 ... -0.5175352  -0.5811472
  -0.0504258 ]]
Enter fullscreen mode Exit fullscreen mode
πŸ‘‹ While you are here

Reinvent your career. Join DEV.

It takes one minute and is worth it for your career.

Get started

Top comments (0)