Here are the examples of the python api numpy.product taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
145 Examples
3
View Complete Implementation : model.py
Copyright Apache License 2.0
Author : google
Copyright Apache License 2.0
Author : google
def set_model_params(self, model_params):
pointer = 0
for i in range(len(self.shapes)):
w_shape = self.shapes[i]
b_shape = self.shapes[i][1]
s_w = np.product(w_shape)
s = s_w + b_shape
chunk = np.array(model_params[pointer:pointer+s])
self.weight[i] = chunk[:s_w].reshape(w_shape)
self.bias[i] = chunk[s_w:].reshape(b_shape)
pointer += s
3
View Complete Implementation : model.py
Copyright Apache License 2.0
Author : google
Copyright Apache License 2.0
Author : google
def set_model_params(self, model_params):
pointer = 0
for i in range(len(self.shapes)):
w_shape = self.shapes[i]
b_shape = self.shapes[i][1]
s_w = np.product(w_shape)
s = s_w + b_shape
chunk = np.array(model_params[pointer:pointer+s])
self.weight[i] = chunk[:s_w].reshape(w_shape)
self.bias[i] = chunk[s_w:].reshape(b_shape)
pointer += s
if self.output_noise[i]:
s = b_shape
self.bias_log_std[i] = np.array(model_params[pointer:pointer+s])
self.bias_std[i] = np.exp(self.sigma_factor*self.bias_log_std[i] + self.sigma_bias)
if self.render_mode:
print("bias_std, layer", i, self.bias_std[i])
pointer += s
3
View Complete Implementation : model_grid_near.py
Copyright Apache License 2.0
Author : google
Copyright Apache License 2.0
Author : google
def set_model_params(self, model_params):
pointer = 0
for i in range(len(self.shapes)):
w_shape = self.shapes[i]
b_shape = self.shapes[i][1]
s_w = np.product(w_shape)
s = s_w + b_shape
chunk = np.array(model_params[pointer:pointer+s])
self.weight[i] = chunk[:s_w].reshape(w_shape)
self.bias[i] = chunk[s_w:].reshape(b_shape)
pointer += s
3
View Complete Implementation : model.py
Copyright Apache License 2.0
Author : google
Copyright Apache License 2.0
Author : google
def set_model_params(self, model_params):
pointer = 0
for i in range(len(self.shapes)):
w_shape = self.shapes[i]
b_shape = self.shapes[i][1]
s_w = np.product(w_shape)
s = s_w + b_shape
chunk = np.array(model_params[pointer:pointer+s])
self.weight[i] = chunk[:s_w].reshape(w_shape)
self.bias[i] = chunk[s_w:].reshape(b_shape)
pointer += s
3
View Complete Implementation : nn.py
Copyright Apache License 2.0
Author : google
Copyright Apache License 2.0
Author : google
def set_model_params(self, model_params):
pointer = 0
for i in range(len(self.shapes)):
w_shape = self.shapes[i]
b_shape = self.shapes[i][1]
s_w = np.product(w_shape)
s = s_w + b_shape
chunk = np.array(model_params[pointer:pointer+s])
self.weight[i] = chunk[:s_w].reshape(w_shape)
self.bias[i] = chunk[s_w:].reshape(b_shape)
pointer += s
# rnn states
s = self.hidden_size
self.init_h = model_params[pointer:pointer+s].reshape((1, self.hidden_size))
self.h = self.init_h
self.rnn = RNNCell(self.input_size, self.weight[0], self.bias[0])
3
View Complete Implementation : mio4.py
Copyright MIT License
Author : ktraunmueller
Copyright MIT License
Author : ktraunmueller
def write_char(self, arr, name):
arr = arr_to_chars(arr)
arr = arr_to_2d(arr, self.oned_as)
dims = arr.shape
self.write_header(
name,
dims,
P=miUINT8,
T=mxCHAR_CLast)
if arr.dtype.kind == 'U':
# Recode unicode to latin1
n_chars = np.product(dims)
st_arr = np.ndarray(shape=(),
dtype=arr_dtype_number(arr, n_chars),
buffer=arr)
st = st_arr.item().encode('latin-1')
arr = np.ndarray(shape=dims, dtype='S1', buffer=st)
self.write_bytes(arr)
3
View Complete Implementation : mio4.py
Copyright MIT License
Author : ktraunmueller
Copyright MIT License
Author : ktraunmueller
def write_char(self, arr, name):
arr = arr_to_chars(arr)
arr = arr_to_2d(arr, self.oned_as)
dims = arr.shape
self.write_header(
name,
dims,
P=miUINT8,
T=mxCHAR_CLast)
if arr.dtype.kind == 'U':
# Recode unicode to latin1
n_chars = np.product(dims)
st_arr = np.ndarray(shape=(),
dtype=arr_dtype_number(arr, n_chars),
buffer=arr)
st = st_arr.item().encode('latin-1')
arr = np.ndarray(shape=dims, dtype='S1', buffer=st)
self.write_bytes(arr)
3
View Complete Implementation : model_grid_fc.py
Copyright Apache License 2.0
Author : google
Copyright Apache License 2.0
Author : google
def set_model_params(self, model_params):
pointer = 0
for i in range(len(self.shapes)):
w_shape = self.shapes[i]
b_shape = self.shapes[i][1]
s_w = np.product(w_shape)
s = s_w + b_shape
chunk = np.array(model_params[pointer:pointer+s])
self.weight[i] = chunk[:s_w].reshape(w_shape)
self.bias[i] = chunk[s_w:].reshape(b_shape)
pointer += s
3
View Complete Implementation : model.py
Copyright Apache License 2.0
Author : google
Copyright Apache License 2.0
Author : google
def set_model_params(self, model_params):
pointer = 0
for i in range(len(self.shapes)):
w_shape = self.shapes[i]
b_shape = self.shapes[i][1]
s_w = np.product(w_shape)
s = s_w + b_shape
chunk = np.array(model_params[pointer:pointer+s])
self.weight[i] = chunk[:s_w].reshape(w_shape)
self.bias[i] = chunk[s_w:].reshape(b_shape)
pointer += s
# rnn states
s = self.hidden_size
self.init_h = model_params[pointer:pointer+s].reshape((1, self.hidden_size))
pointer += s
self.init_c = model_params[pointer:pointer+s].reshape((1, self.hidden_size))
self.reset_state()
self.lstm = LSTMCell(self.obs_size + self.action_size, self.weight[0], self.bias[0], dropout_keep_prob=self.dropout_keep_prob, train_mode=self.train_mode)
3
View Complete Implementation : test_multiarray_assignment.py
Copyright MIT License
Author : ktraunmueller
Copyright MIT License
Author : ktraunmueller
def _check_astignment(srcidx, dstidx):
"""Check astignment arr[dstidx] = arr[srcidx] works."""
arr = np.arange(np.product(shape)).reshape(shape)
cpy = arr.copy()
cpy[dstidx] = arr[srcidx]
arr[dstidx] = arr[srcidx]
astert np.all(arr == cpy), 'astigning arr[%s] = arr[%s]' % (dstidx, srcidx)