41 lines
1.0 KiB
Python
41 lines
1.0 KiB
Python
import os
|
|
import numpy as np
|
|
|
|
def print_numpy(x, val=True, shp=False):
|
|
"""Print the mean, min, max, median, std, and size of a numpy array
|
|
|
|
Parameters:
|
|
val (bool) -- if print the values of the numpy array
|
|
shp (bool) -- if print the shape of the numpy array
|
|
"""
|
|
x = x.astype(np.float64)
|
|
if shp:
|
|
print('shape,', x.shape)
|
|
if val:
|
|
x = x.flatten()
|
|
print('mean = %3.3f, min = %3.3f, max = %3.3f, median = %3.3f, std=%3.3f' % (
|
|
np.mean(x), np.min(x), np.max(x), np.median(x), np.std(x)))
|
|
|
|
|
|
def mkdirs(paths):
|
|
"""create empty directories if they don't exist
|
|
|
|
Parameters:
|
|
paths (str list) -- a list of directory paths
|
|
"""
|
|
if isinstance(paths, list) and not isinstance(paths, str):
|
|
for path in paths:
|
|
mkdir(path)
|
|
else:
|
|
mkdir(paths)
|
|
|
|
|
|
def mkdir(path):
|
|
"""create a single empty directory if it didn't exist
|
|
|
|
Parameters:
|
|
path (str) -- a single directory path
|
|
"""
|
|
if not os.path.exists(path):
|
|
os.makedirs(path)
|