Skip to main content
Solved

Subtract list values from eachother based on index.

  • September 5, 2017
  • 5 replies
  • 201 views

jatoxa
Contributor
Forum|alt.badge.img+12

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!

 

 

 

Best answer by danilo_fme

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

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

5 replies

danilo_fme
Celebrity
Forum|alt.badge.img+52
  • Celebrity
  • Best Answer
  • September 5, 2017

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


david_r
Celebrity
  • September 5, 2017

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.


jatoxa
Contributor
Forum|alt.badge.img+12
  • Author
  • Contributor
  • September 5, 2017

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

 

 


jatoxa
Contributor
Forum|alt.badge.img+12
  • Author
  • Contributor
  • September 5, 2017

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

 

 


danilo_fme
Celebrity
Forum|alt.badge.img+52
  • Celebrity
  • September 5, 2017
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