Generalized pyramids of numbers in ecosystems