generalizing ann on a multidementional output case