Skip to main content
Solved

Subtract list values from eachother based on index.

  • September 5, 2017
  • 5 replies
  • 172 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

View original
Did this help you find an answer to your question?

5 replies

danilo_fme
Evangelist
Forum|alt.badge.img+44
  • Evangelist
  • 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
danilo_fme wrote:

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
david_r wrote:

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
Evangelist
Forum|alt.badge.img+44
  • Evangelist
  • September 5, 2017
jatoxa wrote:
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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings