diff --git a/spec2nii/fileiobase.py b/spec2nii/fileiobase.py index bffc93f..485b1ea 100644 --- a/spec2nii/fileiobase.py +++ b/spec2nii/fileiobase.py @@ -59,6 +59,7 @@ import os import string import itertools +import operator from functools import reduce import numpy as np @@ -511,7 +512,7 @@ def index2trace_flat(shape, index): # by the corresponding index element, index[-1] as added at the beginning a = index[-1] for i, v in enumerate(index[:-1]): - mult = reduce(lambda x, y: x * y, shape[i + 1:]) + mult = reduce(operator.mul, shape[i + 1:]) a = a + mult * v return a diff --git a/spec2nii/varian.py b/spec2nii/varian.py index be8cae4..0961ae2 100644 --- a/spec2nii/varian.py +++ b/spec2nii/varian.py @@ -73,6 +73,7 @@ import os import struct import inspect +import operator from warnings import warn from functools import reduce @@ -659,7 +660,7 @@ def order_data(data, torder): """ # determine the shape of the on disk data matrix - ntraces = reduce(lambda x, y: x * y, data.shape[:-1]) + ntraces = reduce(operator.mul, data.shape[:-1]) nshape = (ntraces, data.shape[-1]) # take care of flat files @@ -1044,7 +1045,7 @@ def write_fid_lowmem(filename, dic, data, torder='f', repack=False, correct=True warn("data and np size mismatch") if correct: dic['np'] = int(data.shape[1] * 2) - nblocks = int(reduce(lambda x, y: x * y, data.shape[:-1])) + nblocks = int(reduce(operator.mul, data.shape[:-1])) if nblocks != dic["nblocks"]: warn("data and block size mismatch") if correct: @@ -2067,7 +2068,7 @@ def __init__(self, filename, i2t_func, fshape=None, order=None): s = "last dimension should have size %i" % (int(dic["np"] / 2)) raise ValueError(s) # product of all but last dim should be number of blocks - if reduce(lambda x, y: x * y, fshape[:-1]) != dic['nblocks']: + if reduce(operator.mul, fshape[:-1]) != dic['nblocks']: s = "number of traces in file does not match fshape" raise ValueError(s)