Solved

Subtract list values from eachother based on index.

  • 5 September 2017
  • 5 replies
  • 32 views

Badge +2

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!

 

 

 

icon

Best answer by danilo_fme 5 September 2017, 17:33

View original

5 replies

Userlevel 4
Badge +30

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

Userlevel 4

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.

Badge +2

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

 

 

Badge +2

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

 

 

Userlevel 4
Badge +30
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