Skip to content

Commit

Permalink
lambda x, y: x * y → operator.mul
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitriPapadopoulos committed Sep 30, 2023
1 parent fee3141 commit 0bbc3b9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion spec2nii/fileiobase.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import os
import string
import itertools
import operator
from functools import reduce

import numpy as np
Expand Down Expand Up @@ -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

Expand Down
7 changes: 4 additions & 3 deletions spec2nii/varian.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
import os
import struct
import inspect
import operator
from warnings import warn
from functools import reduce

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 0bbc3b9

Please sign in to comment.