Here are the examples of the python api numpy.nditer taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
70 Examples
3
View Complete Implementation : cnn.py
Copyright GNU General Public License v3.0
Author : apachecn
Copyright GNU General Public License v3.0
Author : apachecn
def element_wise_op(array, op):
'''
Desc:
element_wise_op函数实现了对numpy数组进行按元素操作,并将返回值写回到数组中
'''
for i in np.nditer(array,
op_flags=['readwrite']):
i[...] = op(i)
3
View Complete Implementation : HiCKRy.py
Copyright MIT License
Author : ay-lab
Copyright MIT License
Author : ay-lab
def outputBias(biasCol, revFrag, outputFilePath):
bpath = outputFilePath
with gzip.open(bpath,'wt') as biasFile:
ctr = 0
for values in np.nditer(biasCol):
chrommidTup = revFrag[ctr]
chrom = chrommidTup[0]
mid = chrommidTup[1]
biasFile.write("%s\t%s\t%s\n" % (chrom, mid, values))
ctr += 1
3
View Complete Implementation : churn_calc.py
Copyright MIT License
Author : carl24k
Copyright MIT License
Author : carl24k
def setup_group_column_names(self,load_mat_df):
N_GROUP_CHAR=7
MAX_GROUP_NAME=10
num_weights = load_mat_df.astype(bool).sum(axis=0)
weight_on_met = load_mat_df.sum(axis=1)
solo_metics = (weight_on_met == 1).to_numpy().nonzero()[0]
grouped_metrics = (num_weights > 1).to_numpy().nonzero()[0]
self.grouped_columns = ['G%d_' % (d + 1) for d in np.nditer(grouped_metrics)]
for m in grouped_metrics:
group_cols = load_mat_df.iloc[:, m].to_numpy().nonzero()[0]
self.grouped_columns[m] += '_'.join(
[load_mat_df.index.values[i][:N_GROUP_CHAR].replace('_', '') for i in group_cols[:MAX_GROUP_NAME]])
self.grouped_columns.extend([load_mat_df.index.values[i] for i in solo_metics])
3
View Complete Implementation : validation.py
Copyright GNU General Public License v3.0
Author : clcr
Copyright GNU General Public License v3.0
Author : clcr
def build_clast_dict(clast_array, no_data=None):
"""Returns a dict of coordinates of the following shape:
[clast, coord].
WARNING: This will take up a LOT of memory!"""
out_dict = {}
it = np.nditer(clast_array, flags=['multi_index'])
while not it.finished:
this_clast = int(it.value)
if this_clast == no_data:
it.iternext()
continue
if this_clast in out_dict.keys():
out_dict[this_clast].append(it.multi_index)
else:
out_dict.update({this_clast: [it.multi_index]})
it.iternext()
return out_dict
3
View Complete Implementation : utils.py
Copyright Apache License 2.0
Author : criteo-research
Copyright Apache License 2.0
Author : criteo-research
def compute_2i_regularization_id(prods, num_products):
"""Compute the ID for the regularization for the 2i approach"""
reg_ids = []
# Loop through batch and compute if the product ID is greater than the number of products
for x in np.nditer(prods):
if x >= num_products:
reg_ids.append(x)
elif x < num_products:
reg_ids.append(x + num_products) # Add number of products to create the 2i representation
return np.asarray(reg_ids)
3
View Complete Implementation : utils.py
Copyright Apache License 2.0
Author : criteo-research
Copyright Apache License 2.0
Author : criteo-research
def compute_treatment_or_control(prods, num_products):
"""Compute if product is in treatment or control"""
# Return the control product places and treatment places as 1's in a binary matrix.
ids = []
for x in np.nditer(prods):
# Greater than the number of products
if x >= num_products:
ids.append(0)
elif x < num_products:
ids.append(1)
# create the binary mask and return
return np.asarray(ids), np.logical_not(np.asarray(ids)).astype(int)
3
View Complete Implementation : png.py
Copyright The Unlicense
Author : DavidWilliams81
Copyright The Unlicense
Author : DavidWilliams81
def write_frame(path, frame, palette):
os.makedirs(path, exist_ok=True)
(plane_count, row_count, col_count) = frame.shape
for plane_idx, plane in enumerate(frame):
imdata = bytearray()
# Note, do we need to specify C vs. Fortran order here?
# https://docs.scipy.org/doc/numpy-1.13.0/reference/arrays.nditer.html
for mat_idx in np.nditer(plane):
rgba = palette[mat_idx]
imdata.extend(rgba)
data = write_png(imdata, col_count, row_count)
with open("{}/{}.png".format(path, plane_idx), 'wb') as fd:
fd.write(data)
3
View Complete Implementation : axis_norm_test.py
Copyright Apache License 2.0
Author : deepmind
Copyright Apache License 2.0
Author : deepmind
def testSimpleCase(self):
layer = axis_norm.LayerNorm([1, 2], create_scale=False, create_offset=False)
inputs = tf.ones([2, 3, 3, 5])
outputs = layer(inputs).numpy()
for x in np.nditer(outputs):
self.astertEqual(x, 0.0)
3
View Complete Implementation : axis_norm_test.py
Copyright Apache License 2.0
Author : deepmind
Copyright Apache License 2.0
Author : deepmind
def testSimpleCaseVar(self):
layer = axis_norm.LayerNorm([1, 2],
create_scale=True,
create_offset=True,
scale_init=initializers.Constant(0.5),
offset_init=initializers.Constant(2.0))
inputs = tf.ones([2, 3, 3, 5])
outputs = layer(inputs).numpy()
for x in np.nditer(outputs):
self.astertEqual(x, 2.0)
3
View Complete Implementation : axis_norm_test.py
Copyright Apache License 2.0
Author : deepmind
Copyright Apache License 2.0
Author : deepmind
def testSimpleCaseNCHWVar(self):
layer = axis_norm.LayerNorm([1, 2],
create_scale=True,
create_offset=True,
scale_init=initializers.Constant(0.5),
offset_init=initializers.Constant(2.0),
data_format="NCHW")
inputs = tf.ones([2, 5, 3, 3])
outputs = layer(inputs).numpy()
for x in np.nditer(outputs):
self.astertEqual(x, 2.0)