How can I get "cumsum" of an array in CGA? Iterate and build a new array recursively in some way?
Hi @MagnusLundevall,
Yes exactly, here is an example:
cumsum(array) = cumsum(array, 1) cumsum(array, i) = case size(array) <= i: array else: cumsum(setElems(array, i, array[i]+array[i-1]), i+1) Init --> print(cumsum([2,5,1,3.5,8]))
May I ask about the usecase? If it is something common we might add it as builtin function in the future, so you don't have to rely on recursion for this.
Cheers,Jonas
I see. Thanks for the informations.
For min/max of an array there is currently no dedicated function, but you can use sortIndices(), there is an example for this case in the cga reference: https://doc.arcgis.com/en/cityengine/latest/cga/cga-sort-indices-function.htm
Thanks! I have used it in trying to solve Split face into rectangular pieces - Esri CommunityI extract scope.sx for each face edge in an array and want to process it to compute split x's. I also had the need for min(array) and max(array) that return the smallest and largest element, respectively. I did write them in the same recursive manner. It would be great to have these in CGA.
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.