Created
February 27, 2024 05:42
-
-
Save curegit/1accba67564e6d5aeaacdbcff49f6dab to your computer and use it in GitHub Desktop.
大規模配列のファイルからの部分読み出し例
This file contains 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
import numpy as np | |
large_arr = np.random.normal(size=(3, 10000, 10000)).astype("float64") | |
np.save("example.npy", large_arr) | |
import time | |
import random | |
from numpy.lib.format import open_memmap | |
s = time.time() | |
mem_array = open_memmap("example.npy", mode="r") | |
channels, height, width = mem_array.shape | |
crop_size = 32 | |
left = random.randrange(width - crop_size) | |
top = random.randrange(height - crop_size) | |
right = left + crop_size | |
bottom = top + crop_size | |
patch = mem_array[:, top:bottom, left:right] | |
print(patch) | |
print(f"{time.time() - s} sec") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment