multiplying

can multiprecision signed multiply be performed with imul instruction?

别等时光非礼了梦想. 提交于 2019-12-24 06:58:46
问题 I am writing a function library to provide all conventional operators and functions for signed-integer types s0128 , s0256 , s0512 , s1024 and floating-point types f0128 , f0256 , f0512 , f1024 . I am writing the s0128 , s0256 , s0512 , s1024 multiply routines now, but am getting erroneous results that confuse me. I assumed I could cascade multiplies with the 64-bit imul rcx instruction (that produces a 128-bit result in rdx:rax ) in the same way I could do the same with unsigned operands

Multiplying complex with constant in C++

删除回忆录丶 提交于 2019-12-23 11:16:08
问题 The following code fails to compile #include <iostream> #include <cmath> #include <complex> using namespace std; int main(void) { const double b=3; complex <double> i(0, 1), comp; comp = b*i; comp = 3*i; return 0; } with error: no match for ‘operator*’ in ‘3 * i’ What is wrong here, why cannot I multiply with immediate constants? b*i works. 回答1: In the first line: comp = b*i; The compiler calls: template<class T> complex<T> operator*(const T& val, const complex<T>& rhs); Which is instanced as

Numpy fusing multiply and add to avoid wasting memory

落爺英雄遲暮 提交于 2019-12-23 09:57:24
问题 Is it possible to multiply two ndarray A, and B and add the result to C, without creating a large intermediate array for A times B? Numpy has the out keyword parameter for the case of C = A times B: numpy.multiply(A, B, out=C) How about the case of C += A times B? 回答1: Numpy only supports operations one at a time. With that said, there are several workarounds. In place operations The most simple solution is to use in-place operations via += and *= import numpy as np import scipy n = 100 b = 5

How do I multiply lists together using a function?

狂风中的少年 提交于 2019-12-20 03:02:08
问题 how do I multiply lists together in python using a function? This is what I have: list = [1, 2, 3, 4] def list_multiplication(list, value): mylist = [] for item in list: for place in value: mylist.append(item*value) return mylist So I want to use this to multiply list*list (1*1, 2*2, 3*3, 4*4) So the output would be 1, 4, 9, and 16. How would I do this in python where the 2nd list could be anything? Thanks 回答1: My favorite way is mapping the mul operator over the two lists: from operator

How to stretch checkbox item the full width of the combobox

隐身守侯 提交于 2019-12-20 02:43:28
问题 I have a multiply combobox with checkbox items <ComboBox x:Name="cmb" IsEditable="True" IsReadOnly="True" DropDownClosed="cmb_DropDownClosed"> <ComboBox.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <CheckBox Content="{Binding NmColumn }" HorizontalAlignment="Stretch" IsChecked="{Binding Path=bChecked, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Tag="{Binding IdColumn}" /> </StackPanel> </DataTemplate> </ComboBox.ItemTemplate> </ComboBox> When I click on checkbox

Using awk how do I combine data in two files and substitute values from the second file to the first file?

我怕爱的太早我们不能终老 提交于 2019-12-19 12:22:44
问题 Any ideas how to the following using awk? Two input files, data.txt and keys.txt: data.txt contains some data: A;1 B;2 A;3 keys.txt contains "key;value" pairs ("C" is in this example not part of data.txt, but the awk script should still work): A;30 B;20 C;10 The output should be as follows: A;1;30 B;2;20 A;3;30 Hence, each row in data.txt that contains any key from keys.txt should get the corresponding value appended to the row in data.txt. 回答1: awk to the rescue! assumes the second file has

Python array multiply

给你一囗甜甜゛ 提交于 2019-12-18 07:40:57
问题 hh=[[82.5], [168.5]] N=1./5 ll=N*hh What I'm doing wrong? I received error : "can't multiply sequence by non-int of type 'float'" I try to add float(), but this is not solve my problem; I need to multiply each element in array... thanks to all **Ok thanks for idea for number * array, but how to multiply array*array, I tried same as number*array, but have problems: EDIT 2:** hh=[[82.5], [168.5]] N=zip(*hh) ll = [[x*N for x in y] for y in hh] ??? 回答1: When you multiply a sequence by X in Python

ufunc 'multiply' did not contain a loop with signature matching types dtype('<U32') dtype('<U32') dtype('<U32')

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-14 02:46:11
问题 I'm trying to write this simple script but for some reason i'm struggling with the mathematical multiply operation. The error that I am getting is ufunc 'multiply' did not contain a loop with signature matching types dtype('<U32') dtype('<U32') dtype('<U32') I am using PyCharm for the first time as editor and I've never had this problem with jupiter. This is my code import numpy as np polar_surfacetension = input('Enter the polar component of the surface tension in mN/m (46.4 for water): ')

Where can I find soft-multiply and divide algorithms?

点点圈 提交于 2019-12-13 11:55:01
问题 I'm working on a micro-controller without hardware multiply and divide. I need to cook up software algorithms for these basic operations that are a nice balance of compact size and efficiency. My C compiler port will employ these algos, not the the C developers themselves. My google-fu is so far turning up mostly noise on this topic. Can anyone point me to something informative? I can use add/sub and shift instructions. Table lookup based algos might also work for me, but I'm a bit worried

Python multiplying all even numbers in a list

萝らか妹 提交于 2019-12-12 05:49:44
问题 I am working on this python code for my first programming class. Yesterday it partially worked but then I changed something and now it is only passing 1 test case. The goal is to multiply all even numbers in list "xs" and return 1 if there are no even numbers. What am I doing wrong and how can I fix it? def evens_product(xs): product = 2 for i in xs: if i%2 == 0: product *= i return product else: return (1) Edit: Chepner's solution worked thank you to everyone who helped 回答1: You need to