How to Caculate High Dimension matrix Dot Product in TensorFlow

2 demensions matrix dot product is easy, however, if the demension is bigger than 2, how to caculate?

Here is an example:

2 dimension matrix dot product

import tensorflow as tf
a =  tf.constant([[1, 2, 3], [4, 5, 6]], dtype=tf.float32)
i =  tf.constant([[2], [7]], dtype=tf.float32)
j = a * i
with tf.Session() as sess:
    sess.run(init) 
    print(sess.run(j))

The result is:

[[ 2.  4.  6.]
 [28. 35. 42.]]

More dimensions matrix dot product

import tensorflow as tf
a =  tf.constant([[[1, 2, 3], [4, 5, 6]],[[1, 6, 3], [4, 3, 6]]], dtype=tf.float32)
i =  tf.constant([[[2], [7]],[[2], [3]]], dtype=tf.float32)
j = a * i
with tf.Session() as sess:
    sess.run(init) 
    print(sess.run(j))

The result is:

[[[ 2.  4.  6.]
  [28. 35. 42.]]

 [[ 2. 12.  6.]
  [12.  9. 18.]]]

Notice: When a and i is not the dimension.

import tensorflow as tf
a =  tf.constant([[[1, 2, 3], [4, 5, 6]],[[1, 6, 3], [4, 3, 6]]], dtype=tf.float32)
i =  tf.constant([[2,2,2], [7,7,7]], dtype=tf.float32)
j = a * i
with tf.Session() as sess:
    sess.run(init) 
    print(sess.run(j))

The result is:

[[[ 2.  4.  6.]
  [28. 35. 42.]]

 [[ 2. 12.  6.]
  [28. 21. 42.]]]

,