How to control dimension broadcast in tensorflow?

Dims

I would like to center my set of rows with several means and get several sets of centered rows.

My data has shape of (4, 3) i.e. four 3D vectors:

data = tf.get_variable("myvar1", shape=[4, 3], dtype=tf.float64)

I have two centers (two 3D vectors):

mu = tf.get_variable("mu", initializer=tf.constant(np.arange(2*3).reshape(2, 3), dtype=tf.float64))

I would like to center data once per each mu. In numpy I would write loop:

data = np.arange(4 * 3).reshape(4, 3)
mu = np.arange(2*3).reshape(2, 3)

centered_data = np.empty((2, 4, 3))
for i_data in range(len(data)):
    for i_mu in range(len(mu)):
        centered = data[i_data] - mu[i_mu]
        centered_data[i_mu, i_data, :] = centered

How to do the same in tensorflow?

Bulk method for numpy would also be appreciated!

Dims

Apparently I can insert singular dimension to provoke broadcasting:

data = tf.get_variable("myvar1", shape=[4, 3], dtype=tf.float64)
mu = tf.get_variable("mu", initializer=tf.constant(np.arange(2*3).reshape(2, 3), dtype=tf.float64))

centered_data = data - tf.expand_dims(mu, axis=1)

with tf.Session() as sess:

    sess.run(tf.global_variables_initializer())

    ans_value, centered_data_value, mu_value = sess.run([centered_data, data, mu], {data: np.arange(4 * 3).reshape(4, 3)})

    print("centered_data_value: ", centered_data_value)
    print("mu: ", mu_value)
    print("ans: ", ans_value)

The same is in numpy:

mu = np.reshape(mu, (2, 1, 3))
centered_data = data - mu

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How to explicitly broadcast a tensor to match another's shape in tensorflow?

分類Dev

Drop a dimension of a tensor in Tensorflow

分類Dev

Iterate over a tensor dimension in Tensorflow

分類Dev

input dimension reshape in Tensorflow conolutional network

分類Dev

Why use None for the batch dimension in tensorflow?

分類Dev

How to broadcast a message using StreamSocket

分類Dev

how to use broadcast receiver with service

分類Dev

Angular: How to $broadcast from Factory?

分類Dev

How to run the broadcast receiver after other broadcast receivers ? android

分類Dev

Tensorflow: zip over first dimension of two tensors of different shape

分類Dev

tensorflow_model_serverAccess-Control-Allow-Origin

分類Dev

How to get the true dimension of a numpy array in python?

分類Dev

How to display scrollbar in list after certain dimension?

分類Dev

How to write a function to translate data to higher dimension

分類Dev

How to get a GeometryReader to work only in one dimension?

分類Dev

MDX: how to get dimension values as columns

分類Dev

How to broadcast Eigen::Tensor to higher dimensions?

分類Dev

How to limit broadcast to its own Android app

分類Dev

How to limit broadcast to its own Android app

分類Dev

How to cut broadcast ip address into another variable

分類Dev

Julia: How to extract a portion of an array along a specified dimension

分類Dev

how to abbreviate dimension following the PEP8 rules?

分類Dev

How to loop over an array sorted by one dimension in Chapel?

分類Dev

How to get pointer to start of ndarray data (of any dimension) in cython

分類Dev

How to distribute a Numpy array along the diagonal of an array of higher dimension?

分類Dev

How position absolute and fixed block elements get their dimension?

分類Dev

How to Keep html table dimension same using DOM

分類Dev

How to Keep html table dimension same using DOM

分類Dev

Keras - How to remove useless dimension without hurting the computation graph?

Related 関連記事

  1. 1

    How to explicitly broadcast a tensor to match another's shape in tensorflow?

  2. 2

    Drop a dimension of a tensor in Tensorflow

  3. 3

    Iterate over a tensor dimension in Tensorflow

  4. 4

    input dimension reshape in Tensorflow conolutional network

  5. 5

    Why use None for the batch dimension in tensorflow?

  6. 6

    How to broadcast a message using StreamSocket

  7. 7

    how to use broadcast receiver with service

  8. 8

    Angular: How to $broadcast from Factory?

  9. 9

    How to run the broadcast receiver after other broadcast receivers ? android

  10. 10

    Tensorflow: zip over first dimension of two tensors of different shape

  11. 11

    tensorflow_model_serverAccess-Control-Allow-Origin

  12. 12

    How to get the true dimension of a numpy array in python?

  13. 13

    How to display scrollbar in list after certain dimension?

  14. 14

    How to write a function to translate data to higher dimension

  15. 15

    How to get a GeometryReader to work only in one dimension?

  16. 16

    MDX: how to get dimension values as columns

  17. 17

    How to broadcast Eigen::Tensor to higher dimensions?

  18. 18

    How to limit broadcast to its own Android app

  19. 19

    How to limit broadcast to its own Android app

  20. 20

    How to cut broadcast ip address into another variable

  21. 21

    Julia: How to extract a portion of an array along a specified dimension

  22. 22

    how to abbreviate dimension following the PEP8 rules?

  23. 23

    How to loop over an array sorted by one dimension in Chapel?

  24. 24

    How to get pointer to start of ndarray data (of any dimension) in cython

  25. 25

    How to distribute a Numpy array along the diagonal of an array of higher dimension?

  26. 26

    How position absolute and fixed block elements get their dimension?

  27. 27

    How to Keep html table dimension same using DOM

  28. 28

    How to Keep html table dimension same using DOM

  29. 29

    Keras - How to remove useless dimension without hurting the computation graph?

ホットタグ

アーカイブ