There is already a version of this function floating around somewhere in multiarray, maybe two. It would be good to unify things.