Question: I have a 2-D tensor **A** with the shape of (?, *L*) which refers to the features obtained through the neural network (where '?' is the batch size), and a 3-D tensor **B** with the shape of (*N*, *K*, *L*). Obviously, there are *N* arrays with the shape of (*K*, *L*) in **B**, which are called **C** here.

Now, how can I calculate the **mean euclidean distance** (average the distance of one row of **A** and each row of **C**) between each row of **A** and every **C** without iterations of every rows in **A** and **C**, and finally return a vector with the shape of (?, *N*) ? 

For example, when the **A** with shape of (1, *L*), the result can be obtained as follows:

```
import tensorflow as tf

with tf.Graph().as_default(), tf.Session() as sess:
    A = tf.placeholder(tf.float32, [1, None])
    B = tf.placeholder(tf.float32, [None, None, None])
    dist = tf.reduce_mean(tf.norm(B - A, axis=2), axis=1)
    print(sess.run(dist, feed_dict={A: [[1, 2, 3]],
                                    B: [[[ 4,  5,  6], [ 7,  8,  9]],
                                        [[10, 11, 12], [13, 14, 15]]]}))
    # [ 7.7942286 18.186533 ]

```

I want to know that when A = ([[1, 2, 3], [4, 5, 6]]) (it is just an example of **A** with the shape of (2, 3)), how can I get the result of the question above with the shape of [2, 2] ?

Answer: 
Dividing by 2 is a simple bitwise right-shift. After @elgonzo's (now deleted) mention of the properties of C#'s rightshift, I decided to have a look how it works, and it *seems* to do exactly what you want:

```
var result = number >> 1;

```

This gives the following results:

11 -> 5  

10 -> 5  

2 -> 1  

1 -> 0  

-1 -> -1  

-2 -> -1  

-32 -> -16  

-33 -> -17 

int.MaxValue and MinValue also work.

Performance-wise, this seems to be almost twice as fast as the currently accepted answer that uses modulo operators.
Dividing (the same) 100000000 random numbers costs 2.17 seconds on my machine using a simple shift, while using the version with modulo's takes between 3.1 and 4.0 seconds. 

The branched versions seem to perform just about the same as the modulo version: significantly slower than the simple rightshift.
If you want to divide `a` by `b`:

**The approach which won't fail because of overflow:**

```
int res = a / b;
return (a < 0 && a != b * res) ? res - 1 : res;

```

**The following approaches may possibly fail because of negative overflow.**

```
int mod = a % b;
if (mod < 0) {
  mod += b;
}
return (a - mod) / b;

```

A mess with `mod += b` because `a % b` can be negative.
A shorter way:

```
return (a - (a % b + b) % b) / b;

```

And more clear one:

```
return a >= 0 ? a / b : (a - b + 1) / b;

```