Skip to main content

Hi,

 

For some reason I have a problem wrapping my head around this and I know it might be easier to solve with a script.

 

 

I have a list containing different numeric values and each value has an index. How would I go about to subtract one value with the next based on the index? For example;

 

 

If index = 5 then subtract value5 from value4

 

If index = 4 then subtract value4 from value3

 

If index = 3 then subtract value3 from value2........ etc.

There could be any number of values in a list so I need to somehow loop through all the values.

 

 

Thanks!

 

 

 

Hi @j2,

My Workspace has this struture bellow:

After i use the ListExploder and the attribute index of list is coming with the new attribute _element_index.

After i used the transformer AttributeManager and use the option Enable Adjacent Feature Attributes.

The result in Data Inspector:

Now you can do substract values.

Attached my template file created.

 

Thanks, - workspace-list.fmwt

Danilo


Could you possibly use the ListIndexer here?

Otherwise this could be a good candidate for a PythonCaller, it's generally much more efficient to loop over (large) lists in Python code than using the ListExploder etc.


Hi @j2,

My Workspace has this struture bellow:

After i use the ListExploder and the attribute index of list is coming with the new attribute _element_index.

After i used the transformer AttributeManager and use the option Enable Adjacent Feature Attributes.

The result in Data Inspector:

Now you can do substract values.

Attached my template file created.

 

Thanks, - workspace-list.fmwt

Danilo

Hi danilo,

 

This works indeed, you more or less just clone and offset the index? Thank you for the solution!

 

 

/Jacob

 

 


Could you possibly use the ListIndexer here?

Otherwise this could be a good candidate for a PythonCaller, it's generally much more efficient to loop over (large) lists in Python code than using the ListExploder etc.

Hi david,

 

 

I have already tested something in that direction.

 

Ultimately I think I will have to make the final solution with Python.

 

 

Thanks for the reply!

 

 

/Jacob

 

 


Hi danilo,

 

This works indeed, you more or less just clone and offset the index? Thank you for the solution!

 

 

/Jacob

 

 

Yes @j2, offset index with transformer AttributeManager

Reply