コード例 #1
0
ファイル: test.py プロジェクト: lihebi/scratch
def main():
    input = np.array([0.5, 2])
    # w1 = np.array([[1,2,3], [3,4,5]])
    w1 = np.array([[1,2,3], [5,4,3]])
    w2 = np.array([3,2,1])

    np.array([[1,2,3],[4,5,6]]).dot(np.array([[1],[2],[3]]))
    np.array([[1,2,3],[4,5,6]]).dot(np.array([1,2,3]))

    np.prod(np.array([1,2,3]), np.array([4,5,6]))
    np.prod([2,3])
    np.prod(np.array([2,3,8]))

    tf.prod([1,2,3])
    
    return (input.dot(w1) + 1).dot(w2)+1
コード例 #2
0
def batch_segment_mean(s_data, s_indices, n):
    s_data_shp = tf.shape(s_data)
    s_data_flat = tf.reshape(s_data,
                             [tf.prod(s_data_shp[:-1]), s_data_shp[-1]])
    s_indices_flat = tf.reshape(s_indices, [-1])
    s_results = tf.unsorted_segment_sum(s_data_flat, s_indices_flat, n)
    s_weights = tf.unsorted_segment_sum(tf.ones_like(s_indices_flat),
                                        s_indices_flat, n)
    return s_results / tf.cast(tf.expand_dims(s_weights, -1), hparams.FLOATX)
コード例 #3
0
def reshape(tensor, dims_ilfst):
    shape = getshape(tensor)
    dims_prod = []
    for dims in dims_list:
        if isinstance(dims, int):
            dims_prod.append(shape[dims])
        elif all([isinstance(shape[d], int)] for d in dims):
            dims_prod.append(np.prod([shape[d] for d in dims]))
        else:
            dims_prod.append(tf.prod([shape[d] for d in dims]))
        tensor = tf.reshape(tensor, dims_prod)
    return tensor
コード例 #4
0
ファイル: ops.py プロジェクト: Zachotha/EffectiveTensorflow
def reshape(tensor, dims_list):
  """Reshape the given tensor by collapsing dimensions."""
  shape = get_shape(tensor)
  dims_prod = []
  for dims in dims_list:
    if isinstance(dims, int):
      dims_prod.append(shape[dims])
    elif all([isinstance(shape[d], int) for d in dims]):
      dims_prod.append(np.prod([shape[d] for d in dims]))
    else:
      dims_prod.append(tf.prod([shape[d] for d in dims]))
  tensor = tf.reshape(tensor, dims_prod)
  return tensor
コード例 #5
0
def reshape(tensor, dims_list):
  """Reshape the given tensor by collapsing dimensions."""
  shape = get_shape(tensor)
  dims_prod = []
  for dims in dims_list:
    if isinstance(dims, int):
      dims_prod.append(shape[dims])
    elif all([isinstance(shape[d], int) for d in dims]):
      dims_prod.append(np.prod([shape[d] for d in dims]))
    else:
      dims_prod.append(tf.prod([shape[d] for d in dims]))
  tensor = tf.reshape(tensor, dims_prod)
  return tensor
コード例 #6
0
 def _num_toks(y):
     return tf.prod(get_shape_as_list(y))