The Operator takes the RapidMiner Object from the input port and delivers copies of it to the output ports. Each connected port creates an independent copy. So changing one copy has no effect on other copies. DifferentiationMany Operators have an output port named original or throughput, which does not change the input. By chaining Operators to one or more original ports also copies of an object can be created. But such a layout can get complicated very fast. The Multiply Operator helps to better structure a RapidMiner Process. Input
Output
Tutorial ProcessesMultiply an ExampleSetIn this tutorial Process the Multiply Operator creates two copies of the Titanic Example Set. All missing values of the first copy are replaced by the average value and then 100 random Examples are selected. The second copy is not modified. This illustrates that the copies are independent and changes on one copy are not applied on the other copies. Initialize the value of the product to 1(not 0 as 0 multiplied with anything returns zero). Traverse till the end of the list, multiply every number with the product. The value stored in the product at the end will give you your final answer. Below is the Python implementation of the above approach: Python
Input : list1 = [3, 2, 4] Output : 240
Input : list1 = [3, 2, 4] Output : 241 Input : list1 = [3, 2, 4] Output : 242
Input : list1 = [3, 2, 4] Output : 243 Input : list1 = [3, 2, 4] Output : 244 Input : list1 = [3, 2, 4] Output : 243 Input : list1 = [3, 2, 4] Output : 246 Input : list1 = [3, 2, 4] Output : 247 Input : list1 = [3, 2, 4] Output : 248 Input : list1 = [3, 2, 4] Output : 243 6 240 6 241 6 242 6 243 6 244 Input : list1 = [3, 2, 4] Output : 246 Input : list1 = [3, 2, 4] Output : 247 Input : list1 = [3, 2, 4] Output : 246 6 248 6 241 Input : list1 = [3, 2, 4] Output : 243 6 241 Input : list1 = [3, 2, 4] Output : 246
6 243 6 244 Input : list1 = [3, 2, 4] Output : 247 6 246 Input : list1 = [3, 2, 4] Output : 248 6 248 6 249 6 248 6 241 6 242 6 243 Input : list1 = [3, 2, 4] Output : 247 6 246 6 241 6 248 6 249 6 248 6 240 6 242 6 242 6 243 6 242 6 245 Output 6 24 Method 2: Using numpy.prod() We can use numpy.prod() from import numpy to get the multiplication of all the numbers in the list. It returns an integer or a float value depending on the multiplication result. Below is the Python3 implementation of the above approach: Python36 246 6 247
6 248 6 249 6 244 Input : list1 = [3, 2, 4] Output : 247 6 246 Input : list1 = [3, 2, 4] Output : 248 6 248 6 249 6 248 6 241 6 242 6 243 Input : list1 = [3, 2, 4] Output : 247 6 246 6 241 6 248 6 249 6 248 6 240 6 242
6 248 6 249 Input : list1 = [3, 2, 4] Output : 247 6 241 6 242 Input : list1 = [3, 2, 4] Output : 247 6 244 6 242 6 246 6 242 6 248 Output: 6 24 Method 3 Using lambda function: Using numpy.array Lambda’s definition does not include a “return” statement, it always contains an expression that is returned. We can also put a lambda definition anywhere a function is expected, and we don’t have to assign it to a variable at all. This is the simplicity of lambda functions. The reduce() function in Python takes in a function and a list as an argument. The function is called with a lambda function and a list and a new reduced result is returned. This performs a repetitive operation over the pairs of the list. Below is the Python3 implementation of the above approach: Python36 246
6 248 # Python program to multiply all values in the 46 244 Input : list1 = [3, 2, 4] Output : 247 6 246 Input : list1 = [3, 2, 4] Output : 248 6 248 6 249 6 248 6 241 6 242 6 243 Input : list1 = [3, 2, 4] Output : 247 6 246 6 241 6 248 6 249 6 248 6 240 6 242
6 249 Input : list1 = [3, 2, 4] Output : 247 # Python program to multiply all values in the 4Input : list1 = [3, 2, 4] Output : 2416 Input : list1 = [3, 2, 4] Output : 2417 Input : list1 = [3, 2, 4] Output : 2418 6 248 Input : list1 = [3, 2, 4] Output : 2420 6 242 Input : list1 = [3, 2, 4] Output : 247 # Python program to multiply all values in the 4Input : list1 = [3, 2, 4] Output : 2416 Input : list1 = [3, 2, 4] Output : 2417 Input : list1 = [3, 2, 4] Output : 2418 6 248 Input : list1 = [3, 2, 4] Output : 2428 6 242 6 246 6 242 6 248 Output 6 24 Method 4 Using prod function of math library: Using math.prod Starting Python 3.8, a prod function has been included in the math module in the standard library, thus no need to install external libraries. Below is the Python3 implementation of the above approach: Python36 246 Input : list1 = [3, 2, 4] Output : 2434
6 248 Input : list1 = [3, 2, 4] Output : 2436 6 244 Input : list1 = [3, 2, 4] Output : 247 6 246 Input : list1 = [3, 2, 4] Output : 248 6 248 6 249 6 248 6 241 6 242 6 243 Input : list1 = [3, 2, 4] Output : 247 6 246 6 241 6 248 6 249 6 248 6 240 6 242
6 249 Input : list1 = [3, 2, 4] Output : 247 Input : list1 = [3, 2, 4] Output : 2457 6 242 Input : list1 = [3, 2, 4] Output : 247 Input : list1 = [3, 2, 4] Output : 2460 6 242 6 246 6 242 6 248 Output: 6 24 Method 5: Using mul() function of operator module. First we have to import the operator module then using the mul() function of operator module multiplying the all values in the list. Python3Input : list1 = [3, 2, 4] Output : 2465 Input : list1 = [3, 2, 4] Output : 2466
Input : list1 = [3, 2, 4] Output : 2468 6 248 6 248 6 244 Input : list1 = [3, 2, 4] Output : 247 6 246 Input : list1 = [3, 2, 4] Output : 248 6 248 6 249 6 248 6 241 6 242 Input : list1 = [3, 2, 4] Output : 2480 Input : list1 = [3, 2, 4] Output : 247 Input : list1 = [3, 2, 4] Output : 248 6 240 Input : list1 = [3, 2, 4] Output : 2484 6 242 Input : list1 = [3, 2, 4] Output : 2486 Input : list1 = [3, 2, 4] Output : 2487 Input : list1 = [3, 2, 4] Output : 2488 Input : list1 = [3, 2, 4] Output : 2487 Input : list1 = [3, 2, 4] Output : 2490 Input : list1 = [3, 2, 4] Output : 243 Input : list1 = [3, 2, 4] Output : 2480 Input : list1 = [3, 2, 4] Output : 247 Input : list1 = [3, 2, 4] Output : 2494 Input : list1 = [3, 2, 4] Output : 2495 6 242 Input : list1 = [3, 2, 4] Output : 2497 Output 6 Method 6: Using traversal by index Python3
Input : list1 = [3, 2, 4] Output : 240
Input : list1 = [3, 2, 4] Output : 241 6 2401 Input : list1 = [3, 2, 4] Output : 243 Input : list1 = [3, 2, 4] Output : 243 Input : list1 = [3, 2, 4] Output : 244 Input : list1 = [3, 2, 4] Output : 243 Input : list1 = [3, 2, 4] Output : 246 Input : list1 = [3, 2, 4] Output : 247 Input : list1 = [3, 2, 4] Output : 248 Input : list1 = [3, 2, 4] Output : 243 6 240 Input : list1 = [3, 2, 4] Output : 2484 6 242 6 2413 6 2414 6 2415 6 248 6 2417 6 2418 |