Skip to content

Instantly share code, notes, and snippets.

@justinhchae
Created May 3, 2022 23:25
Show Gist options
  • Save justinhchae/620c893fe18bf5bbbeefba21e11e6b87 to your computer and use it in GitHub Desktop.
Save justinhchae/620c893fe18bf5bbbeefba21e11e6b87 to your computer and use it in GitHub Desktop.
A simple working example of how to use compressed numpy storage for data such as point clouds and classes.
'''https://numpy.org/doc/stable/reference/generated/numpy.savez_compressed.html#numpy.savez_compressed
'''
import numpy as np
import os
# number of points in the point cloud
num_points = 10
# a random array that is in a typical xyz arrangement
points = np.random.rand(num_points, 3)
# a random 1d array representing classes for each point
classes = np.random.randint(low=0, high=3, size=(num_points,))
# setting up a place to save and then read data
CURR_DIR = os.getcwd()
filename = 'gt_points.npz' # or pd_points
filepath = os.path.join(CURR_DIR, filename)
# use np to save a compressed file that can access each array by keyword
np.savez_compressed(filepath, points=points, classes=classes)
loaded = np.load(filepath)
# the loaded arrays are the same as they were originally stored
print(loaded['points'] == points)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment