Question: Let **M** and **n** be **d x d**- and **d**-dimensonal numpy arrays of integers, respectively. I want to count the number of triples of the form *(n(i), n(j), M(i,j))*. As a result I want a numpy array such that each entry counts the number of occurences of such a triple.

*Edit:* **M** is symmetric and I don't want to count triples with i=j.

I'm currently using `itertools.product` (for loop over all pairs) and `numpy.bincount` to do this, but it is too slow. Is there a smarter way doing this, probably using `numpy`?

Answer: 
Say you have a 4 digit int which has to be 24 hour time between 0000 and 2359

```
public static boolean isValid(int time) {
     int mins = time % 100;
     return mins < 60 && hrs >= 0 && hrs < 2400;
}

```

Say it is between 0001 and 2400

```
public static boolean isValid(int time) {
     int mins = time % 100;
     return mins < 60 && time >= 1 && time <= 2400;
}

```
I like the response of Peter. Attaching my code which was based on Peter's response.

```
package general;

public class ClockPlay {
    ClockPlay() {}

    public static boolean isValidTime (int time){
        int mins = time % 100;
        System.out.println("Mins is:" + mins);
        return (mins >= 0 && mins < 60 && time >= 0 && time <= 2400);
    }

    public static void main(String[] args) {
        int time1 = 1245;
        int time2 = 2510;

        System.out.println("Validity of Time 1 is:" + isValidTime(time1));
        System.out.println("Validity of Time 2 is:" + isValidTime(time2));
    }

}

```

Output:

```
Mins is:45
Validity of Time 1 is:true
Mins is:10
Validity of Time 2 is:false

```