multiplication

Compute the product of the next n elements in array

白昼怎懂夜的黑 提交于 2019-12-22 08:52:06
问题 I would like to compute the product of the next n adjacent elements of a matrix. The number n of elements to be multiplied should be given in function's input. For example for this input I should compute the product of every 3 consecutive elements, starting from the first. [p, ind] = max_product([1 2 2 1 3 1],3); This gives [1*2*2, 2*2*1, 2*1*3, 1*3*1] = [4,4,6,3] . Is there any practical way to do it? Now I do this using: for ii = 1:(length(v)-2) p = prod(v(ii:ii+n-1)); end where v is the

x86 assembly multiply and divide instruction operands, 16-bit and higher

霸气de小男生 提交于 2019-12-21 08:22:58
问题 I'm rather confused about how the multiply and divide operations work in x86 assembly. For example, the code below doesn't seem too difficult since deals with 8-bit. 8-Bit Multiplication: ; User Input: ; [num1], 20 ; [num2] , 15 mov ax, [num1] ; moves the 8 bits into AL mov bx, [num2] ; moves the 8 bits into BL mul bl ; product stored in AX print ax But what happens when you want to multiply two 16-bit numbers? How would one multiply two 16 bit numbers the same way as it has been done with

Understanding Schönhage-Strassen algorithm (huge integer multiplication)

夙愿已清 提交于 2019-12-20 19:59:22
问题 I need to multiply several 1000s digits long integers as efficiently as possible in Python. The numbers are read from a file. I am trying to implement the Schönhage-Strassen algorithm for integer multiplication, but I am stuck on understanding the definition and mathematics behind it, specially the Fast Fourier Transform. Any help to understand this algorithm, like a practical example or some pseudo-code would be highly appreciated. 回答1: Chapter 4.3.3 of Knuth's TAOCP describes it and also

Understanding Schönhage-Strassen algorithm (huge integer multiplication)

拟墨画扇 提交于 2019-12-20 19:59:13
问题 I need to multiply several 1000s digits long integers as efficiently as possible in Python. The numbers are read from a file. I am trying to implement the Schönhage-Strassen algorithm for integer multiplication, but I am stuck on understanding the definition and mathematics behind it, specially the Fast Fourier Transform. Any help to understand this algorithm, like a practical example or some pseudo-code would be highly appreciated. 回答1: Chapter 4.3.3 of Knuth's TAOCP describes it and also

TASM:How to printout a register pair dx:ax on screen after multiply?

大憨熊 提交于 2019-12-20 07:45:19
问题 include io.h cr equ 0dh lf equ 0ah stacksg segment stack dw 100 dup(?) stacksg ends datasg segment prp1 db '1st Number:',cr,lf,0 prp2 db '2nd Number:',cr,lf,0 prp3 db 'The result:',cr,lf,0 numA dw ? numB dw ? sum dw 20 dup(?),0 entersim db cr,lf datasg ends codesg segment start: assume cs:codesg,ds:datasg mov ax,datasg mov ds,ax output prp1 inputs numA,10 atoi numA mov numA,ax output prp2 inputs numB,10 atoi numB mov bx,ax mov ax,numA mul bx itoa sum,ax output entersim output prp3 output sum

Multiplication of two 16-bit numbers - Why is the result 32-bit long? [closed]

那年仲夏 提交于 2019-12-20 07:34:50
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . If I multiplie two 16-bit numbers, the result will be 32-bit long. But why is this so? What is the clear explanation for this? And for my right understanding: The calculation for this is: n-bit number multiplied with a m-bit number gives a (n+m) bit number? 回答1: (2 n - 1)*(2 m - 1) = 2 n+m - 2 n - 2 m + 1 -(2 n

Multiplication of two 16-bit numbers - Why is the result 32-bit long? [closed]

左心房为你撑大大i 提交于 2019-12-20 07:34:15
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . If I multiplie two 16-bit numbers, the result will be 32-bit long. But why is this so? What is the clear explanation for this? And for my right understanding: The calculation for this is: n-bit number multiplied with a m-bit number gives a (n+m) bit number? 回答1: (2 n - 1)*(2 m - 1) = 2 n+m - 2 n - 2 m + 1 -(2 n

Why doesn't std::string define multiplication or literals? [closed]

梦想与她 提交于 2019-12-20 06:25:37
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . In the language I was first introduced to, there was a function repeat() , that took a string, and repeated it n times. For example,

Strange multiplication result

六月ゝ 毕业季﹏ 提交于 2019-12-20 06:15:18
问题 In my code I have this multiplications in a C++ code with all variable types as double[] f1[0] = (f1_rot[0] * xu[0]) + (f1_rot[1] * yu[0]); f1[1] = (f1_rot[0] * xu[1]) + (f1_rot[1] * yu[1]); f1[2] = (f1_rot[0] * xu[2]) + (f1_rot[1] * yu[2]); f2[0] = (f2_rot[0] * xu[0]) + (f2_rot[1] * yu[0]); f2[1] = (f2_rot[0] * xu[1]) + (f2_rot[1] * yu[1]); f2[2] = (f2_rot[0] * xu[2]) + (f2_rot[1] * yu[2]); corresponding to these values Force Rot1 : -5.39155e-07, -3.66312e-07 Force Rot2 : 4.04383e-07, -1

How do I multiply a dataframe column by a float constant?

我的梦境 提交于 2019-12-20 05:22:03
问题 I'm trying to multiply a column by a float. I have the code for it here: if str(cMachineName)==str("K42"): df_temp.loc[:, "P"] *= float((105.0* 59.0*math.pi*0.95/1000)/3540) But it gives me this error: TypeError: can't multiply sequence by non-int of type 'float'. How do I solve it? 回答1: I think problem is some non numeric values like 45 as string: Solution is converting to float , int by astype: df_temp = pd.DataFrame({'P':[1,2.5,'45']}) print (df_temp['P'].dtype) object df_temp["P"] = df