1
vote
1answer
33 views

Single Byte Multiplication in Python?

I have a requirement to decode a file using simple byte multiplication For every byte in the file, the byte value is muliplied by 0x69. The result cannot be a word, it must be a single byte. ...
1
vote
2answers
53 views

Elementwise multiplication of several arrays in Python Numpy

Coding some Quantum Mechanics routines, I have discovered a curious behavior of Python's NumPy. When I use NumPy's multiply with more than two arrays, I get faulty results. In the code below, i have ...
0
votes
1answer
133 views

Karatsuba algorithm incorrect result

I just simply followed the pseudo code on wiki http://en.wikipedia.org/wiki/Karatsuba_algorithm But the result of this implementation is very unstable. It works sometimes but in case like 100*100. It ...
0
votes
2answers
84 views

Simple Multiplication of two fields in OpenErp

I have two fields in a class, in a third field i need the multiplication result of the two fields declared before. For example: _columns = { 'Item' : fields.integer('Items'), ...
1
vote
1answer
100 views

A function that takes two matrices as input, and returns a matrix with A * B. In Python

I am trying to figure out how to create a dot product matrix. Here is the code I have made so far: C = [[4,1,9], [6,2,8], [7,3,5]] D = [[2,9], [5,2], [1,0]] def prettyPrint(A): for i in ...
1
vote
4answers
66 views

How to multiply each row in a matrix by each column in the second matrix in Python?

I know the steps to multiply two matrices are as follow Step 1: Make sure that the the number of columns in the 1st one equals the number of rows in the 2nd one. Step 2: Multiply the elements of ...
6
votes
3answers
2k views

Python: multiply all items in a list together

I have a problem. I need to write a function, that takes a list of numbers and multiply them together. example: [1,2,3,4,5,6] will give me 1*2*3*4*5*6. I could really use your help.
0
votes
1answer
165 views

Matrix multiplication in Python

Hello (excuse my English), I have a big doubt in python with matrix multiplication, I create a list of lists and multiplied by a scaling matrix, this is what I've done and I can not alparecer perform ...
3
votes
5answers
103 views

Multiply Adjacent Elements

I have a tuple of integers such as (1, 2, 3, 4, 5) and I want to produce the tuple (1*2, 2*3, 3*4, 4*5) by multiplying adjacent elements. Is it possible to do this with a one-liner?
-2
votes
3answers
311 views

How do I multiple all integers in a list? --Python

list1= [1,2,3,4] 1) I want to multiply every element in this list in order to output 24. How do I do this in python without using a for loop? Are there in-built libraries to do this? 2) And what ...
0
votes
1answer
374 views

Strassen Matrix Multiplication — close, but still with bugs

I'm trying to implement Strassen Matrix multiplication in Python. I've got it working somewhat. Here's my code: a = [[1,1,1,1],[2,2,2,2],[3,3,3,3],[4,4,4,4]] b = ...
1
vote
7answers
266 views

multiplication game python

I am supposed to write a program in python that asks the user how many multiplication questions they want, and it randomly gives them questions with values from 1 to 10. Then it spits out the ...
1
vote
1answer
188 views

Multiplying two polynomials mod n,x^r-1 using long integers: what is the correct window size?

Using a window multiplication algorithm to multiply two polynomials[coefficients in Z/nZ and the whole polynomial mod x^r-1 for some r] using long-integer multiplications, what size should I give to ...
1
vote
3answers
211 views

Python and Powers Math

I've been learning Python but I'm a little confused. Online instructors tell me to use the operator ** as opposed to ^ when I'm trying to raise to a certain number. Example: print 8^3 Gives an ...
-2
votes
3answers
114 views

Multiply matrix by list in Python

I am looking for a way to achieve the following in Python and can't figure out how to do it: a=[[0,1],[1,0],[1,1]] b=[1,0,5] c=hocuspocus(a,b) --> c=[[0,1],[0,0],[5,5]] So basically I would ...
7
votes
2answers
487 views

Elementwise multiplication of arrays of different shapes in python

Say I have two arrays a and b, a.shape = (5,2,3) b.shape = (2,3) then c = a * b will give me an array c of shape (5,2,3) with c[i,j,k] = a[i,j,k]*b[j,k]. Now the situation is, a.shape = ...
1
vote
1answer
1k views

Vector Matrix multiplication in python?

So I'm trying to multiply a matrix by a vector. And python keeps on throwing up an error. Here is the code that I'm trying: def matmult(m, v): rows = len(m) w = [0]*rows irange = ...
1
vote
2answers
426 views

Karatsuba algorithm in Python

So I am implementing Karatsuba's multiplication algorithm in python. Right now I have infinite recursion and cannot figure it out. Any ideas? I will provide more code if needed. def multiply(self, ...
3
votes
2answers
632 views

Elementwise multiply 1D-numpy arrays (shapes (k,1) or (k,)) and have result have the shape of the first

I would like to implement a diagonal matrix apply function that is created by providing the diagonal d first, and then doing a bunch of matrix-vector multiplications with x. Of course I wouldn't want ...
0
votes
1answer
172 views

Python: division and multiplication of timedelta64 type with floats

I am having difficulties multiplying the numpy datatype timedelta64 with floats. For a task i need to calculate the period of a star using Kepler's second law. There are a lot of data points, so I ...
1
vote
4answers
796 views

Python Multiplying Integers inside “print()”

So I have the code (Relevant code): print("You have chosen to bet on the even numbers") valin = input("How much would you like to bet?: ") print("If it lands on an even number, you win", valin*2) ...
0
votes
5answers
349 views

Why do I get an error when I call int(input()) where input is decimal (eg. '87.94')?

I'm a programming newbie having difficulty with Python multiplication. I have code like this: def getPriceDiscount(): price = int(input()) if price > 3000: priceDiscount = price * ...
0
votes
1answer
122 views

Prevent overflow errors when multiplying and powering in Python

How would you prevent the errors when calling function biased_random defined below and what are the limits for arguments scale and bias to hold for preventing problems with big or small numbers? def ...
0
votes
1answer
291 views

Lattice Multiplication with threads, is it more efficient?

which one is faster: Using Lattice Multiplication with threads(big numbers) OR Using common Multiplication with threads(big numbers) Do you know any source code, to test them? ...
7
votes
4answers
995 views

Karatsuba algorithm too much recursion

I am trying to implement the Karatsuba multiplication algorithm in c++ but right now I am just trying to get it to work in python. Here is my code: def mult(x, y, b, m): if max(x, y) < b: ...
9
votes
4answers
2k views

Python list multiplication: [[…]]*3 makes 3 lists which mirror each other when modified

Why this is happening? I don't really understand: >>> P = [ [()]*3 ]*3 >>> P [[(), (), ()], [(), (), ()], [(), (), ()]] >>> P[0][0]=1 >>> P [[1, (), ()], [1, (), ...
1
vote
7answers
1k views

Having trouble with multiplying a variable with a number

I'm trying to shorten my code and have more functionality but its not working right. Heres my code(basically) def times4(): number = droid.dialogGetInput('Input', 'Enter a number between 1 and ...
3
votes
2answers
578 views

Deepcopy on nested referenced lists created by list multiplication does not work

As much as I love Python, the reference and deepcopy stuff sometimes freaks me out. Why does deepcopy not work here: >>> import copy >>> a = 2*[2*[0]] >>> a [[0, 0], [0, ...
2
votes
3answers
214 views

Python basic maths

My friend wrote up this script for me to calculate the quantity of construction materials needed for a theoretical site. It basically takes 2 numbers and increases them independently until the large ...
4
votes
4answers
4k views

Python long multiplication

I'm in need of an algorithm faster than the current normal python long multiplication , I tried to find a decent karatsuba implementation , but I can't. def main(): a=long(raw_input()) ...