The shape of the two result arrays (*val and *pos) must be must be obtained from the shape of the source array by deleting dimension dim. The mask array must be the same shape as the source array (see section 4.4).