パイクラおじさんの日記

MinecraftでPythonを勉強するおじさんの日記です。

NumPy配列の分割を使って4次メッシュを作成

# coding: utf-8

import numpy as np
import matplotlib.pyplot as plt
import sys

NPY_DIR = "/Users/pycra/Desktop"
NPY_FILE = "npydata-{0:04d}-{1:02d}-{2:02d}.npy"
NPYDIV5_FILE = "npydiv5-{0:04d}-{1:02d}-{2:02d}-{3:02d}.npy"


# ここからスタート

if len(sys.argv) < 4:
    print("npydiv5.py mesh1 mesh2 mesh3")
    exit(-1)

mesh1 = int(sys.argv[1])
mesh2 = int(sys.argv[2])
mesh3 = int(sys.argv[3])

array = np.load(NPY_DIR+"/"+NPY_FILE.format(mesh1, mesh2, mesh3))

a = np.split(array, 5, axis=1)
#print("a=", a)

count = 0
for j in range(5):
    b = np.split(a[j], 5, axis=0)
    #print("b=", b)
    for i in range(5):
        np.save(NPY_DIR+"/"+NPYDIV5_FILE.format(mesh1, mesh2, mesh3, count), b[i])
        count+=1