FAQ Database Discussion Community

## Python's Multiplication Function

python,formatting,multiplication,presentation
In python I found a multiplication solution very useful for the software I am writing. Problem is when using the software, user is asked a question (i.e 8x2) but it prints a command-type line (i.e 14). This is not so user friendly and I would like to display it in...

## PHP - Double Recursive Multiplication [closed]

php,recursion,numbers,multiplication
Im creating a function to calculate prices for my business, but im stuck on one point \$cost = 5.4; \$price = \$cost + (\$price*0.105) + (\$price*0.1); How i can do this math? It´s a recursive formula but i dont see the solution.. I tried to search but havent see the...

## Need help in writing this multiplication code

c,formatting,output,multiplication,spaces
I need to show process of multiplication in output.for ex:- inputs are two numbers(say 325 and 4405) the output would be:- 325 *4405 ----- 1625 0 1300 1300 ------- 1431625 NOTE:-number of spaces should be minimum. I don't need the exact code. Just tell me which property or way I...

## Multiplication of two arrays in numpy

python,python-2.7,numpy,multiplication
I have two numpy arrays: x = numpy.array([1, 2]) y = numpy.array([3, 4]) And I would like to create a matrix of elements products: [[3, 6], [4, 8]] What is the easiest way to do this?...

## Karatsuba algorithm - Error in my implementation

python,algorithm,multiplication
I'm having trouble to implement the karatsuba algorithm in python. I'm working with lists in base 2 (the MSB is at the end in the list). The implementation given to me is this: Input: 2 bit-numbers of bit length n Output: their product a*b function Karatsuba(a, b) if(n == 1)...

## Issues With length() And Multiples Of 3

java,math,multiplication,string-length
Lets see if someone can wrap their head around this: if you get the length of a String using length(), the String always being multiples of 3,(in my case: "1.02.03.04.05.06.07.0 etc.") each 3 characters representing a letter, with .1 indicating a capitol letter, how do you use the length to...

## Time complexity of russian peasant multiplication algorithm?

c++,algorithm,multiplication
I want to know that what is the time complexity of this piece of code which is Russian peasant Implementation unsigned long long int russian(unsigned long long int a, unsigned long long int b) { unsigned long long int res = 0; while (b > 0) { if (b &...

## Python 3: Multiply a vector by a matrix without NumPy

python,matrix,vector,multiplication
I'm fairly new to Python and trying to create a function to multiply a vector by a matrix (of any column size). e.g.: multiply([1,0,0,1,0,0], [[0,1],[1,1],[1,0],[1,0],[1,1],[0,1]]) [1, 1] Here is my code: def multiply(v, G): result = [] total = 0 for i in range(len(G)): r = G[i] for j in...

## Is it possible to speed up matrix multiplication with texture memory?

c++,matrix,cuda,multiplication
I am learning cuda. Would it be possible to speedup something as simple as matrix multiplication with texture memory? The spatial locality is a nice property as addition to my tiling, but could overhead from using texture memory outweigh it? I can't seem to find any implementations of matrix multiplication...

## Getting the high part of 64 bit integer multiplication [duplicate]

c++,assembly,64bit,multiplication
This question already has an answer here: Efficient computation of the high order bits of a multiplication 3 answers In C++, say that: uint64_t i; uint64_t j; then i * j will yield an uint64_t that has as value the lower part of the multiplication between i and j,...

## Divide by 9 without using division or multiplication operator

c,algorithm,math,multiplication,integer-division
This question I have tried to solve it but couldn't get any way. Any pointers would be appreciated. Regular subtraction way of doing division is not the intention here, ingenious way of using shifting operator to get this done is the intention....

## Python multiplication quiz syntax error [closed]

python,syntax,syntax-error,multiplication
while writing a program which overall creates a quiz of 10 multiplication questions for a user, I have encountered a syntax error which I have been unsuccessful in fixing. When I try to run the code, there is a syntax error, pointing to the colon after "if userAns == numAns:"...

## Python Multiplication Error (version 3.4)

python,math,python-3.x,multiplication
I have been using Python 2.7 since very soon after it was released. I just recently had problems with 2.7 not doing everything I needed, so I updated (finally). However, after a few days, I am noticing some problems with multiplication. But is it something I'm doing or a problem...

## Multiplication of 32 bits numbers in C

c,64bit,32-bit,multiplication,fixed-point
Why the below code produces this error? error: left shift count >= width of type [-Werror] The code: int32_t a,b; int64_t apo; a = 2673; b = 19; apo = BIG_MULL(a,b); printf("\n %ld \n", apo ); The macros found here: #define WORD_MASK ((1<<16) - 1) #define LOW_WORD(x) (x & WORD_MASK)...

## Conditional subtraction Part 2

r,conditional,multiplication
I have a big data.frame (TOTAL) with some values (cols11-16) that I need to subtract a base from which is multiplied by a value depending on two conditions in TOTAL. The data.frame (TOTAL) looks a little like this Channel Hour Category cols11 cols12 cols13 cols14 cols15 base TV1 01:00:00 New...

## TypeError: 'int' object is not subscriptable (python)

python,object,matrix,int,multiplication
I'm having problems making a matrix multiplication algorithm in python3. This is the code: def matrixMult(m1, m2): result = [[0 for x in range(len(m1))] for x in range(len(m2[0]))] # Iterate through rows of m1. for i in range(len(m1)): # Iterate through columns of m2. for j in range(len(m2[0])): # Iterate...

## Multiply newly entered row with another column value and find Total Sum in SQL

sql,sql-server,sum,multiplication
I have 4 tables here, I need to multiply newly entered row value in a table with another row and find the total sum using CustomerId: CustomerTable: CustomerId Name EmailId ------------------------- 1 Paul [email protected] 2 John [email protected] LoyaltyPointTable: LoyaltyPointsId LoyaltyType Points --------------------------------------- 1 Registration 10 2 Loginstatus 1 3 Downloading...

## How would I output this multiplication table with an if statement?

c++,arrays,if-statement,multiplication,n-dimensional
#include <iostream> #include <string> #include <cmath> using namespace std; int main() { char response = 'y'; while (response == 'y') do { const int myarray = 144; int thearray[myarray]; for (int m = 0; m < 12; m++) { cout << m + 1 << " "; } cout <<...

## Is there a functional difference between “x = -x” and “x *= -1” when negating values?

c++,c,multiplication,negative-number
Code example: float f = 123.456; int i = 12345; // negate by changing sign i = -i; f = -f; // negate by multiplying with -1 i *= -1; f *= -1.0f; Apart from aesthetics, is there any factual reason why one should prefer one way over the other?...

## Implementing Karatsuba Multiplication in javascript?

javascript,algorithm,data-structures,multiplication
I have tried to implement karatsuba algorithm using the below code.The problem starts when the number of digits in x and y(parameters) mismatch as the recursive call doesn't work in that case with the below logic. As of now, am getting the correct output when the number of digits in...

## Mysteries of C++ optimization

c++,optimization,bit-shift,multiplication
Take the two following snippets: int main() { unsigned long int start = utime(); __int128_t n = 128; for(__int128_t i=1; i<1000000000; i++) n = (n * i); unsigned long int end = utime(); cout<<(unsigned long int) n<<endl; cout<<end - start<<endl; } and int main() { unsigned long int start =...

## PHP - Best way to print multiplication table [closed]

php,list,loops,multiplication
Basic PHP. I decided to print a list of 10 multiples of 17.5, like: 17.5 | 35 | 52.5 | 70 | 87.5 | 105 | 122.5 | 140 | 157.5 | 175 | So I first used this loop: <?php \$number = 17.5; \$result = 0; \$i = 0;...

## Perform integer division using multiplication

assembly,optimization,bit-manipulation,division,multiplication
Looking at x86 assembly produced by a compiler, I noticed that (unsigned) integer divisions are sometimes implemented as integer multiplications. These optimizations seem to follow the form value / n => (value * ((0xFFFFFFFF / n) + 1)) / 0x100000000 For example, performing a division by 9: 12345678 / 9...

## Floating point numbers multiplication in verilog

floating-point,verilog,multiplication
I want to get the 16-bit data for floating point multiplication but the resutls was wrong and not what I demanded.By the way is the real must be in 64 pin? module calc(input [15:0]a, b, output [15:0]o); assign o = a * b; endmodule here is the testbench: module calc_tb();...

## Kronecker product between two tensors

matlab,matrix,vectorization,multiplication
I have two tensor: x is 2-by-2-by-3, y is also 2-by-2-by-3. Define each frontal slice of tensor is x1 x2 x3,y1,y2,y3. xi or yi are 2-by-2 matrix. How can I do kronecker product between x and y in matlab? What I want to get is kron(x1,y1),kron(x2,y2),kron(x3,y3) in matlab simultaneously without...

## Why cuSparse is much slower than cuBlas for sparse matrix multiplication

matrix,cuda,multiplication,sparse,cublas
Recently when I used cuSparse and cuBlas in CUDA TOOLKIT 6.5 to do sparse matrix multiplication, I find cuSparse is much slower than cuBlas in all cases! In all my experiments, I used "cusparseScsrmm" in cuSparse and "cublasSgemm" in cuBlas. In the sparse matrix, half of the total elements are...

## Multiplication Digits Solver in Python

python,python-2.7,multiplication
I am creating a program in Python that finds the digits that can match the letters of the following multiplication, for example: OTTO x ____I STOP ( meaning OTTO x I = STOP ) Here is the code I've been working on, but it doesn't seem to stop... # OTTO...

## Making a Matrix element equals the row number times the column number in matlab [duplicate]

arrays,matlab,matrix,matrix-multiplication,multiplication
This question already has an answer here: Create a matrix with A(i, j) = i*j 3 answers I want to declare a function that takes (n, m) as inputs an return mt as a n-by-m matrix. and if I assume that the row number (rn) and the column number...

## Filtering and multiplying filtered matrix in matlab

matlab,matrix,filter,multiplication
I'd like to filter my matrix according to a specified criteria, then doing multiplication on filtered matrix and then joining multiplied filtered matrix with remainder part of matrix. E.g. I've matrix a as follows: a = 1 2 3 4 4 5 6 2 then, i'm going to filter it...

## Non-matching values for modulus and p*q in RSA encryption

c#,encryption,encoding,biginteger,multiplication
I am currently doing a cryptography project which involves RSA encryption. I used the RSACryptoServiceProvider class to generate the values p, q and n (modulus). Since n = pq, I decided to test if the two values (i.e. pq and n) match. When I used the BigInteger class to multiply...

## Exact decimal arithmetic in Julia

floating-point,julia-lang,multiplication
Due to the nature of floating-point math, .4 * .4 = 0.16000000000000003 in Julia. I want to get the mathematically correct answer of 0.16, in a CPU-efficient way. I know round() works, but that requires prior knowledge of the number of decimal places the answer occupies, so it isn't a...

## VHDL simulation stuck in for loop

loops,vhdl,multiplication
I'm doing simulation testing for some VHDL I wrote and when I run it in ModelSim it gets stuck. When I hit 'break' it has an arrow pointing to the For loop in the following function: function MOD_3 (a, b, c : UNSIGNED (1023 downto 0)) return UNSIGNED is VARIABLE...