use y.ndim

since you use array2d above you'll never enter this branching.