the above check for ndim should be in the condition.