Could you please make this work for arrays with arbitrary shape?

You would need to replace `len(times)` with `times.size` and then do a reshape at the end to `times.shape`.