def compute_std(self, file_list, mean_vector):
logger = logging.getLogger("acoustic_norm")
std_vector = numpy.zeros((1, self.feature_dimension))
all_frame_number = 0
io_funcs = BinaryIOCollection()
for file_name in file_list:
features = io_funcs.load_binary_file(file_name, self.feature_dimension)
current_frame_number = features.size / self.feature_dimension
mean_matrix = numpy.tile(mean_vector, (current_frame_number, 1))
std_vector += numpy.reshape(numpy.sum((features - mean_matrix) ** 2, axis=0), (1, self.feature_dimension))
all_frame_number += current_frame_number
std_vector /= float(all_frame_number)
std_vector = std_vector ** 0.5
# po=numpy.get_printoptions()
# numpy.set_printoptions(precision=2, threshold=20, linewidth=1000, edgeitems=4)
logger.info('computed std vector of length %d' % std_vector.shape[1] )
logger.info(' std: %s' % std_vector)
# restore the print options
# numpy.set_printoptions(po)
return std_vector
python类get_printoptions()的实例源码
def find_min_max_values(self, in_file_list, start_index, end_index):
local_feature_dimension = end_index - start_index
file_number = len(in_file_list)
min_value_matrix = numpy.zeros((file_number, local_feature_dimension))
max_value_matrix = numpy.zeros((file_number, local_feature_dimension))
io_funcs = BinaryIOCollection()
for i in xrange(file_number):
features = io_funcs.load_binary_file(in_file_list[i], self.feature_dimension)
temp_min = numpy.amin(features[:, start_index:end_index], axis = 0)
temp_max = numpy.amax(features[:, start_index:end_index], axis = 0)
min_value_matrix[i, ] = temp_min;
max_value_matrix[i, ] = temp_max;
self.min_vector = numpy.amin(min_value_matrix, axis = 0)
self.max_vector = numpy.amax(max_value_matrix, axis = 0)
self.min_vector = numpy.reshape(self.min_vector, (1, local_feature_dimension))
self.max_vector = numpy.reshape(self.max_vector, (1, local_feature_dimension))
# po=numpy.get_printoptions()
# numpy.set_printoptions(precision=2, threshold=20, linewidth=1000, edgeitems=4)
self.logger.info('found min/max values of length %d:' % local_feature_dimension)
self.logger.info(' min: %s' % self.min_vector)
self.logger.info(' max: %s' % self.max_vector)
# restore the print options
# numpy.set_printoptions(po)
def compute_std(self, file_list, mean_vector, start_index, end_index):
local_feature_dimension = end_index - start_index
std_vector = numpy.zeros((1, self.feature_dimension))
all_frame_number = 0
io_funcs = BinaryIOCollection()
for file_name in file_list:
features, current_frame_number = io_funcs.load_binary_file_frame(file_name, self.feature_dimension)
mean_matrix = numpy.tile(mean_vector, (current_frame_number, 1))
std_vector += numpy.reshape(numpy.sum((features[:, start_index:end_index] - mean_matrix) ** 2, axis=0), (1, local_feature_dimension))
all_frame_number += current_frame_number
std_vector /= float(all_frame_number)
std_vector = std_vector ** 0.5
# po=numpy.get_printoptions()
# numpy.set_printoptions(precision=2, threshold=20, linewidth=1000, edgeitems=4)
self.logger.info('computed std vector of length %d' % std_vector.shape[1] )
self.logger.info(' std: %s' % std_vector)
# restore the print options
# numpy.set_printoptions(po)
return std_vector
def compute_mean(self, file_list, start_index, end_index):
logger = logging.getLogger('feature_normalisation')
local_feature_dimension = end_index - start_index
mean_vector = numpy.zeros((1, local_feature_dimension))
all_frame_number = 0
io_funcs = BinaryIOCollection()
for file_name in file_list:
features, current_frame_number = io_funcs.load_binary_file_frame(file_name, self.feature_dimension)
mean_vector += numpy.reshape(numpy.sum(features[:, start_index:end_index], axis=0), (1, local_feature_dimension))
all_frame_number += current_frame_number
mean_vector /= float(all_frame_number)
# setting the print options in this way seems to break subsequent printing of numpy float32 types
# no idea what is going on - removed until this can be solved
# po=numpy.get_printoptions()
# numpy.set_printoptions(precision=2, threshold=20, linewidth=1000, edgeitems=4)
logger.info('computed mean vector of length %d :' % mean_vector.shape[1] )
logger.info(' mean: %s' % mean_vector)
# restore the print options
# numpy.set_printoptions(po)
self.mean_vector = mean_vector
return mean_vector
def compute_std(self, file_list, mean_vector, start_index, end_index):
logger = logging.getLogger('feature_normalisation')
local_feature_dimension = end_index - start_index
std_vector = numpy.zeros((1, self.feature_dimension))
all_frame_number = 0
io_funcs = BinaryIOCollection()
for file_name in file_list:
features, current_frame_number = io_funcs.load_binary_file_frame(file_name, self.feature_dimension)
mean_matrix = numpy.tile(mean_vector, (current_frame_number, 1))
std_vector += numpy.reshape(numpy.sum((features[:, start_index:end_index] - mean_matrix) ** 2, axis=0), (1, local_feature_dimension))
all_frame_number += current_frame_number
std_vector /= float(all_frame_number)
std_vector = std_vector ** 0.5
# setting the print options in this way seems to break subsequent printing of numpy float32 types
# no idea what is going on - removed until this can be solved
# po=numpy.get_printoptions()
# numpy.set_printoptions(precision=2, threshold=20, linewidth=1000, edgeitems=4)
logger.info('computed std vector of length %d' % std_vector.shape[1] )
logger.info(' std: %s' % std_vector)
# restore the print options
# numpy.set_printoptions(po)
self.std_vector = std_vector
return std_vector
def find_min_max_values(self, in_file_list, start_index, end_index):
local_feature_dimension = end_index - start_index
file_number = len(in_file_list)
min_value_matrix = numpy.zeros((file_number, local_feature_dimension))
max_value_matrix = numpy.zeros((file_number, local_feature_dimension))
io_funcs = BinaryIOCollection()
for i in xrange(file_number):
features = io_funcs.load_binary_file(in_file_list[i], self.feature_dimension)
temp_min = numpy.amin(features[:, start_index:end_index], axis = 0)
temp_max = numpy.amax(features[:, start_index:end_index], axis = 0)
min_value_matrix[i, ] = temp_min;
max_value_matrix[i, ] = temp_max;
self.min_vector = numpy.amin(min_value_matrix, axis = 0)
self.max_vector = numpy.amax(max_value_matrix, axis = 0)
self.min_vector = numpy.reshape(self.min_vector, (1, local_feature_dimension))
self.max_vector = numpy.reshape(self.max_vector, (1, local_feature_dimension))
# po=numpy.get_printoptions()
# numpy.set_printoptions(precision=2, threshold=20, linewidth=1000, edgeitems=4)
self.logger.info('found min/max values of length %d:' % local_feature_dimension)
self.logger.info(' min: %s' % self.min_vector)
self.logger.info(' max: %s' % self.max_vector)
# restore the print options
# numpy.set_printoptions(po)
def compute_mean(self, file_list, start_index, end_index):
logger = logging.getLogger('feature_normalisation')
local_feature_dimension = end_index - start_index
mean_vector = numpy.zeros((1, local_feature_dimension))
all_frame_number = 0
io_funcs = BinaryIOCollection()
for file_name in file_list:
features, current_frame_number = io_funcs.load_binary_file_frame(file_name, self.feature_dimension)
mean_vector += numpy.reshape(numpy.sum(features[:, start_index:end_index], axis=0), (1, local_feature_dimension))
all_frame_number += current_frame_number
mean_vector /= float(all_frame_number)
# setting the print options in this way seems to break subsequent printing of numpy float32 types
# no idea what is going on - removed until this can be solved
# po=numpy.get_printoptions()
# numpy.set_printoptions(precision=2, threshold=20, linewidth=1000, edgeitems=4)
logger.info('computed mean vector of length %d :' % mean_vector.shape[1] )
logger.info(' mean: %s' % mean_vector)
# restore the print options
# numpy.set_printoptions(po)
self.mean_vector = mean_vector
return mean_vector
def compute_std(self, file_list, mean_vector, start_index, end_index):
logger = logging.getLogger('feature_normalisation')
local_feature_dimension = end_index - start_index
std_vector = numpy.zeros((1, self.feature_dimension))
all_frame_number = 0
io_funcs = BinaryIOCollection()
for file_name in file_list:
features, current_frame_number = io_funcs.load_binary_file_frame(file_name, self.feature_dimension)
mean_matrix = numpy.tile(mean_vector, (current_frame_number, 1))
std_vector += numpy.reshape(numpy.sum((features[:, start_index:end_index] - mean_matrix) ** 2, axis=0), (1, local_feature_dimension))
all_frame_number += current_frame_number
std_vector /= float(all_frame_number)
std_vector = std_vector ** 0.5
# setting the print options in this way seems to break subsequent printing of numpy float32 types
# no idea what is going on - removed until this can be solved
# po=numpy.get_printoptions()
# numpy.set_printoptions(precision=2, threshold=20, linewidth=1000, edgeitems=4)
logger.info('computed std vector of length %d' % std_vector.shape[1] )
logger.info(' std: %s' % std_vector)
# restore the print options
# numpy.set_printoptions(po)
self.std_vector = std_vector
return std_vector
test_arrayprint.py 文件源码
项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda
作者: SignalMedia
项目源码
文件源码
阅读 23
收藏 0
点赞 0
评论 0
def setUp(self):
self.oldopts = np.get_printoptions()
def compute_mean(self, file_list, start_index, end_index):
logger = logging.getLogger('feature_normalisation')
local_feature_dimension = end_index - start_index
mean_vector = numpy.zeros((1, local_feature_dimension))
all_frame_number = 0
io_funcs = HTKFeat_read()
for file_name in file_list:
features, current_frame_number = io_funcs.getall(file_name)
# io_funcs = HTK_Parm_IO()
# io_funcs.read_htk(file_name)
# features = io_funcs.data
# current_frame_number = io_funcs.n_samples
mean_vector += numpy.reshape(numpy.sum(features[:, start_index:end_index], axis=0), (1, local_feature_dimension))
all_frame_number += current_frame_number
mean_vector /= float(all_frame_number)
# setting the print options in this way seems to break subsequent printing of numpy float32 types
# no idea what is going on - removed until this can be solved
# po=numpy.get_printoptions()
# numpy.set_printoptions(precision=2, threshold=20, linewidth=1000, edgeitems=4)
logger.info('computed mean vector of length %d :' % mean_vector.shape[1] )
logger.info(' mean: %s' % mean_vector)
# restore the print options
# numpy.set_printoptions(po)
self.mean_vector = mean_vector
return mean_vector
def compute_std(self, file_list, mean_vector, start_index, end_index):
logger = logging.getLogger('feature_normalisation')
local_feature_dimension = end_index - start_index
std_vector = numpy.zeros((1, self.feature_dimension))
all_frame_number = 0
io_funcs = HTKFeat_read()
for file_name in file_list:
features, current_frame_number = io_funcs.getall(file_name)
mean_matrix = numpy.tile(mean_vector, (current_frame_number, 1))
std_vector += numpy.reshape(numpy.sum((features[:, start_index:end_index] - mean_matrix) ** 2, axis=0), (1, local_feature_dimension))
all_frame_number += current_frame_number
std_vector /= float(all_frame_number)
std_vector = std_vector ** 0.5
# setting the print options in this way seems to break subsequent printing of numpy float32 types
# no idea what is going on - removed until this can be solved
# po=numpy.get_printoptions()
# numpy.set_printoptions(precision=2, threshold=20, linewidth=1000, edgeitems=4)
logger.info('computed std vector of length %d' % std_vector.shape[1] )
logger.info(' std: %s' % std_vector)
# restore the print options
# numpy.set_printoptions(po)
self.std_vector = std_vector
return std_vector
def printoptions(*args, **kwargs):
original = numpy.get_printoptions()
numpy.set_printoptions(*args, **kwargs)
yield
numpy.set_printoptions(**original)
def find_min_max_values(self, in_file_list):
logger = logging.getLogger("acoustic_norm")
file_number = len(in_file_list)
min_value_matrix = numpy.zeros((file_number, self.feature_dimension))
max_value_matrix = numpy.zeros((file_number, self.feature_dimension))
io_funcs = BinaryIOCollection()
for i in xrange(file_number):
features = io_funcs.load_binary_file(in_file_list[i], self.feature_dimension)
temp_min = numpy.amin(features, axis = 0)
temp_max = numpy.amax(features, axis = 0)
min_value_matrix[i, ] = temp_min;
max_value_matrix[i, ] = temp_max;
self.min_vector = numpy.amin(min_value_matrix, axis = 0)
self.max_vector = numpy.amax(max_value_matrix, axis = 0)
self.min_vector = numpy.reshape(self.min_vector, (1, self.feature_dimension))
self.max_vector = numpy.reshape(self.max_vector, (1, self.feature_dimension))
# po=numpy.get_printoptions()
# numpy.set_printoptions(precision=2, threshold=20, linewidth=1000, edgeitems=4)
logger.info('across %d files found min/max values of length %d:' % (file_number,self.feature_dimension) )
logger.info(' min: %s' % self.min_vector)
logger.info(' max: %s' % self.max_vector)
# restore the print options
# numpy.set_printoptions(po)
def find_min_max_values(self, in_file_list, start_index, end_index):
local_feature_dimension = end_index - start_index
file_number = len(in_file_list)
min_value_matrix = numpy.zeros((file_number, local_feature_dimension))
max_value_matrix = numpy.zeros((file_number, local_feature_dimension))
io_funcs = BinaryIOCollection()
for i in xrange(file_number):
features = io_funcs.load_binary_file(in_file_list[i], self.feature_dimension)
temp_min = numpy.amin(features[:, start_index:end_index], axis = 0)
temp_max = numpy.amax(features[:, start_index:end_index], axis = 0)
min_value_matrix[i, ] = temp_min;
max_value_matrix[i, ] = temp_max;
self.min_vector = numpy.amin(min_value_matrix, axis = 0)
self.max_vector = numpy.amax(max_value_matrix, axis = 0)
self.min_vector = numpy.reshape(self.min_vector, (1, local_feature_dimension))
self.max_vector = numpy.reshape(self.max_vector, (1, local_feature_dimension))
# po=numpy.get_printoptions()
# numpy.set_printoptions(precision=2, threshold=20, linewidth=1000, edgeitems=4)
self.logger.info('found min/max values of length %d:' % local_feature_dimension)
self.logger.info(' min: %s' % self.min_vector)
self.logger.info(' max: %s' % self.max_vector)
# restore the print options
# numpy.set_printoptions(po)
def compute_std(self, file_list, mean_vector, start_index, end_index):
local_feature_dimension = end_index - start_index
std_vector = numpy.zeros((1, self.feature_dimension))
all_frame_number = 0
io_funcs = BinaryIOCollection()
for file_name in file_list:
features, current_frame_number = io_funcs.load_binary_file_frame(file_name, self.feature_dimension)
mean_matrix = numpy.tile(mean_vector, (current_frame_number, 1))
std_vector += numpy.reshape(numpy.sum((features[:, start_index:end_index] - mean_matrix) ** 2, axis=0), (1, local_feature_dimension))
all_frame_number += current_frame_number
std_vector /= float(all_frame_number)
std_vector = std_vector ** 0.5
# po=numpy.get_printoptions()
# numpy.set_printoptions(precision=2, threshold=20, linewidth=1000, edgeitems=4)
self.logger.info('computed std vector of length %d' % std_vector.shape[1] )
self.logger.info(' std: %s' % std_vector)
# restore the print options
# numpy.set_printoptions(po)
return std_vector
def compute_mean(self, file_list, start_index, end_index):
logger = logging.getLogger('feature_normalisation')
local_feature_dimension = end_index - start_index
mean_vector = numpy.zeros((1, local_feature_dimension))
all_frame_number = 0
io_funcs = BinaryIOCollection()
for file_name in file_list:
features, current_frame_number = io_funcs.load_binary_file_frame(file_name, self.feature_dimension)
mean_vector += numpy.reshape(numpy.sum(features[:, start_index:end_index], axis=0), (1, local_feature_dimension))
all_frame_number += current_frame_number
mean_vector /= float(all_frame_number)
# setting the print options in this way seems to break subsequent printing of numpy float32 types
# no idea what is going on - removed until this can be solved
# po=numpy.get_printoptions()
# numpy.set_printoptions(precision=2, threshold=20, linewidth=1000, edgeitems=4)
logger.info('computed mean vector of length %d :' % mean_vector.shape[1] )
logger.info(' mean: %s' % mean_vector)
# restore the print options
# numpy.set_printoptions(po)
self.mean_vector = mean_vector
return mean_vector
def compute_std(self, file_list, mean_vector, start_index, end_index):
logger = logging.getLogger('feature_normalisation')
local_feature_dimension = end_index - start_index
std_vector = numpy.zeros((1, self.feature_dimension))
all_frame_number = 0
io_funcs = BinaryIOCollection()
for file_name in file_list:
features, current_frame_number = io_funcs.load_binary_file_frame(file_name, self.feature_dimension)
mean_matrix = numpy.tile(mean_vector, (current_frame_number, 1))
std_vector += numpy.reshape(numpy.sum((features[:, start_index:end_index] - mean_matrix) ** 2, axis=0), (1, local_feature_dimension))
all_frame_number += current_frame_number
std_vector /= float(all_frame_number)
std_vector = std_vector ** 0.5
# setting the print options in this way seems to break subsequent printing of numpy float32 types
# no idea what is going on - removed until this can be solved
# po=numpy.get_printoptions()
# numpy.set_printoptions(precision=2, threshold=20, linewidth=1000, edgeitems=4)
logger.info('computed std vector of length %d' % std_vector.shape[1] )
logger.info(' std: %s' % std_vector)
# restore the print options
# numpy.set_printoptions(po)
self.std_vector = std_vector
return std_vector
def _printoptions(*args, **kwargs):
original = np.get_printoptions()
np.set_printoptions(*args, **kwargs)
yield
np.set_printoptions(**original)
# http://code.activestate.com/recipes/577586-converts-from-decimal-to-any-base-between-2-and-26/
def setUp(self):
self.oldopts = np.get_printoptions()
def parse_numpy_printoption(kv_str):
"""Sets a single numpy printoption from a string of the form 'x=y'.
See documentation on numpy.set_printoptions() for details about what values
x and y can take. x can be any option listed there other than 'formatter'.
Args:
kv_str: A string of the form 'x=y', such as 'threshold=100000'
Raises:
argparse.ArgumentTypeError: If the string couldn't be used to set any
nump printoption.
"""
k_v_str = kv_str.split("=", 1)
if len(k_v_str) != 2 or not k_v_str[0]:
raise argparse.ArgumentTypeError("'%s' is not in the form k=v." % kv_str)
k, v_str = k_v_str
printoptions = np.get_printoptions()
if k not in printoptions:
raise argparse.ArgumentTypeError("'%s' is not a valid printoption." % k)
v_type = type(printoptions[k])
if v_type is type(None):
raise argparse.ArgumentTypeError(
"Setting '%s' from the command line is not supported." % k)
try:
v = (v_type(v_str) if v_type is not bool
else flags.BooleanParser().Parse(v_str))
except ValueError as e:
raise argparse.ArgumentTypeError(e.message)
np.set_printoptions(**{k: v})