Here are the examples of the python api numpy.switch taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
1 Examples
0
Example 1
Project: pylearn2 Source File: gsn.py
@staticmethod
def _apply_clamping(activations, clamped, symbolic=True):
"""
Resets the value of some layers within the network.
Parameters
----------
activations : list
List of symbolic tensors representing the current activations.
clamped : list of (int, matrix, matrix or None) tuples
The first component of each tuple is an int representing the
index of the layer to clamp.
The second component is a matrix of the initial values for that
layer (ie what we are resetting the values to).
The third component is a matrix mask indicated which indices in
the minibatch to clamp (1 indicates clamping, 0 indicates not).
The value of None is equivalent to the 0 matrix (so no clamping).
If symbolic is true then matrices are Theano tensors, otherwise
they should be numpy matrices.
symbolic : bool, optional
Whether to execute with symbolic Theano tensors or numpy matrices.
"""
for idx, initial, clamp in clamped:
if clamp is None:
continue
# take values from initial
clamped_val = clamp * initial
# zero out values in activations
if symbolic:
activations[idx] = T.switch(clamp, initial, activations[idx])
else:
activations[idx] = np.switch(clamp, initial, activations[idx])
return activations