multiplication

Multiply Numpy n x 2 array by n x 1 array

Multiply Numpy n x 2 array by n x 1 array Question: Assuming I have a Numpy n x 2 array y: array([[1, 1], [2, 3], [1, 4], …]) and a Numpy n x 1 array x: array([2, 4, 5, …]), how can I efficiently obtain the following result, n x 2 array: array([2, 2], …

Total answers: 1

Fractional multiplications – unexpected results of positive numbers

Fractional multiplications – unexpected results of positive numbers Question: I am getting unexpected results when multiplying 2 fractional numbers. If i use a calculator (google) to check my sums, i get the correct answer (or the answer i am expecting) This is an example of the sum i am trying to do abs(-0.00012437234926353282 * 0.2) …

Total answers: 1

Multiply different size nested array with scalar

Multiply different size nested array with scalar Question: In my python code, I have an array that has different size inside like this arr = [ [1], [2,3], [4], [5,6,7], [8], [9,10,11] ] I want to multiply them by 10 so it will be like this arr = [ [10], [20,30], [40], [50,60,70], [80], [90,100,110] …

Total answers: 2

Elements multiplication in NumPy array with all other elements

Elements multiplication in NumPy array with all other elements Question: If I have a NumPy array [a b c d], is there a way to get the sum of the multiplication of each element with all other elements excluding itself and without duplicates? For example, the sum for this array would be: ab + ac …

Total answers: 2

getting no result but stuck in infinite loop in karatsuba algorithm

getting no result but stuck in infinite loop in karatsuba algorithm Question: I am not getting any result my program stuck in infinite loop. I made a program for four values with same logic which worked great but with three values this is not working def Karatsuba_Recursive(a, b): if not a or not b: return …

Total answers: 1

getting wrong output with algorithm which is like Karatsuba

getting wrong output with algorithm which is like Karatsuba Question: I made a program to multiply two strings and I expected 1000*10 = 10000, but I am getting 100000. I don’t know where my logic is wrong. I also tried replacing m2 with m1 in the expression ((val3+val4) * 10**(m2)) but nothing works, and when …

Total answers: 2

Getting Unexpected Result in Python in Multiplication

Getting Unexpected Result in Python in Multiplication Question: I Made a program to multiply two large numbers but did,nt get expected result When I Use My Program Result("1131231231231231232132176453243264237453265745327432747324575342321321321324234234324234243242343213","3242342342342342343243212341234") I Got 3667838920001082329580291288441145791080382201626879559138562006502209700363203527339095217292763913228365618564468855268114011142 But When I Directly multiply these numbers in python i get 1131231231231231232132176453243264237453265745327432747324575342321321321324234234324234243242343213 * 3242342342342342343243212341234 3667838920001082167184590525973693204469083965208483826796404950051845708090751087384204216926015556670850912511772595077899944842 Both are Different. def Result(val1,val2): array = [] offset …

Total answers: 1

How to multiply Tensorflow arrays across specified indicies

How to multiply Tensorflow arrays across specified indicies Question: I would like to multiply two Tensorflow Arrays in a certain way as shown in the code below: import tensorflow as tf from tensorflow.keras import mixed_precision policy = mixed_precision.Policy(‘mixed_float16’) mixed_precision.set_global_policy(policy) print(‘Compute dtype: %s’ % policy.compute_dtype) print(‘Variable dtype: %s’ % policy.variable_dtype) a = tf.random.normal(shape=[1000, 1439]) b = …

Total answers: 1

Pandas multiplication of two dataframes with uneven date rows and label columns

Pandas multiplication of two dataframes with uneven date rows and label columns Question: I have the following sample of historical Bitcoin rates in US dollars: BTC_USD_rates = { "Open": {"01/01/2022": 46217.5, "02/01/2022": 47738.7, "03/01/2022": 47293.9, "04/01/2022": 46435.7, "05/01/2022": 45833.1, "06/01/2022": 43431.6, "07/01/2022": 43097.9, "08/01/2022": 41551.3}, "Low": {"01/01/2022": 46217.5, "02/01/2022": 46718.2, "03/01/2022": 45704.0, "04/01/2022": 45602.1, "05/01/2022": …

Total answers: 2

Open parenthesis of sympy Mul

Open parenthesis of sympy Mul Question: I have the following expression multiplying two expressions: from sympy import * c1, c2, x = symbols("c1, c2, x") expr = c2*x*(c1*x + c2*x) I would like to be able to open the parenthesis, so that this expression would be c1*c2*x**2 + c2**2*x**2 I need this because I want …

Total answers: 1