# Row multiply

Is there an easy way to do a row (or column) multiply?  I have to rows of numbers I want to apply simple mathmatical functions to (multiple, add, etc.) that aren't in the statistics node.  I didn't see a node that would all me to do what I wanted, so I tried a jpython 2:1 node.

The script I used is:

`iterator = inData0.iterator()`
`while iterator.hasNext():`
`    row1 = iterator.next()`

`iterator = inData1.iterator()`
`while iterator.hasNext():`
`    row2 = iterator.next()`

`out1 = [i*j for i,j in zip(row1,row2)]`
`outContainer.addRowToTable(out1)`

This doesn't work in the KNIME jpython node, but it is the correct sytax for Python lists.  I assume this has something to do with the fact that the row objects aren't lists, but I can't seem to make the conversion, look up help for the conversion, or do the same type of math with the row objects.

Any suggestions to use KNIME nodes for the same calculation or a way to fix the python code?

One way to add/multiply two rows together is to transpose the table first with "transpose" and then use the "Maths Formula" node.

Any use?

Simon.

Ugh, that is exactly what I was looking for.  I just hadn't found that extension.  I had assumed basic math operations would be easy, thanks for the help.

I have to do this transposition trick all the time. It would be nice to have equivalent operators for both rows and columns?

Hi,

you can use GroupBy node to compute the sum, product etc. of all rows in a data table just select no column as group column in the first tab of the node dialog and add all columns as aggregation column with the appropriate aggregation method (sum, etc.) on the second tab.

To compute the sum, product of all columns per row you could use the Column Aggregator node. Just select the columns that should be included on the first tab and the aggregation methods e.g. sum on the second tab.

Bye,

Tobias

Hello,

your hints did confuse me. I want to calculate the difference between two rows and add the result to a new column.

```Row 1: 42
Row 2: 99
Row 3: 100 ```

and the result shoud be

```Row 1: 42   42
Row 2: 99   57
Row 3: 100 1```

I tried to transpose the table and I also tried GroupBy node. Could not find the right settings :-(

Any help welcome!

@stefferber

Knime is now many versions on since the original post so it's got much easier to do this.

take your original table, and use a Lag Column node of interval 1. Then use a Maths Formula node to subtract the original column from the new column.

you'll note your first row is missing, if this is important, then you'll need to do a few extra steps at the beginning.

take a Table Creator node, enter in a column by the exact same column name as the column with your numbers in it. Make sure it's type is set to integer or double. Then in the first row enter 0. Now use concatenate node to join it to your table. This can also be done another way with Create Table Structure node followed by Add empty Rows node, and then Concatenate node.

simon.

Thanks a lot. This was easy once you know how to do. I would never have figured it out myself ;-)