multiplying

Measuring time in C

佐手、 提交于 2019-11-27 12:23:25
问题 I'm trying to measure some activity in C (Matrix multiplying) and noticed that I should do something like this: clock_t start = clock(); sleep(3); clock_t end = clock(); double elapsed_time = (end - start)/(double)CLOCKS_PER_SEC; printf("Elapsed time: %.2f.\n", elapsed_time); The output is: Elapsed time: 0.00. Why is this happening? 回答1: clock estimates the CPU time used by your program; that's the time the CPU has been busy executing instructions belonging to your program. sleep doesn't

Vector multiplication using MATMUL in Fortran

丶灬走出姿态 提交于 2019-11-27 09:32:08
I am trying to multiply part of a column vector (n,1) by a part of another row vector (1,n). Both parts have the same length. So I should get a matrix (n,n). Here is my simple code: PROGRAM test_pack_1 REAL :: m(1,10), x(10,1), y(10,10) m = reshape( (/ 1, -1, 3, 2, 1, 2, -2, -2, 1, 0 /), (/ 1, 10 /)) x = reshape( (/ 1, 0, 1, 1, 0, 1, 1, 0, 1, 0 /), (/ 10, 1 /)) y(1:9,1:9) = MATMUL(x(1:9,1),m(1,1:9)) DO j = 1,10 PRINT* ;WRITE(*,*) y(:,j) ENDDO print * END PROGRAM I'm Using: ifort -g -debug -traceback -check all -ftrapuv test_cshift.f90 And I'm getting: test_cshift.f90(7): error #6241: The

C#, Operator '*' cannot be applied to operands of type 'double' and 'decimal'

╄→尐↘猪︶ㄣ 提交于 2019-11-26 21:48:19
问题 This error should be a simple one but I cant seem to make it work. The problem lies in the fact that this very same code works earlier in the program. I don's see any reason for it to be sending an error on this instance and not the four previous ones. Reference the code below, and feel free to provide any criticism you may have as it should make me better. If it matters, I am using Sharp Develop 2.2. Here is an example of the code that works: void calc2Click(object sender, EventArgs e) { if

How can a query multiply 2 cell for each row MySQL?

时光怂恿深爱的人放手 提交于 2019-11-26 17:22:23
问题 I want to multiply 2 cells for each row and put the value of that in the last column called Total. Can this be done by a normal query? Example: Pieces | Price | Total 6 | 4 | null // should be 24 2 | 10 | null // should be 10 回答1: Use this: SELECT Pieces, Price, Pieces * Price as 'Total' FROM myTable 回答2: You can do it with: UPDATE mytable SET Total = Pieces * Price; 回答3: I'm assuming this should work. This will actually put it in the column in your database UPDATE yourTable yt SET yt.Total =

Vector multiplication using MATMUL in Fortran

浪子不回头ぞ 提交于 2019-11-26 14:47:32
问题 I am trying to multiply part of a column vector (n,1) by a part of another row vector (1,n). Both parts have the same length. So I should get a matrix (n,n). Here is my simple code: PROGRAM test_pack_1 REAL :: m(1,10), x(10,1), y(10,10) m = reshape( (/ 1, -1, 3, 2, 1, 2, -2, -2, 1, 0 /), (/ 1, 10 /)) x = reshape( (/ 1, 0, 1, 1, 0, 1, 1, 0, 1, 0 /), (/ 10, 1 /)) y(1:9,1:9) = MATMUL(x(1:9,1),m(1,1:9)) DO j = 1,10 PRINT* ;WRITE(*,*) y(:,j) ENDDO print * END PROGRAM I'm Using: ifort -g -debug

How to multiply two arrays element-wise

眉间皱痕 提交于 2019-11-26 11:34:28
问题 I need to multiply an array by another array element-wise, just like the Hadamard product of vectors in math. For example: A = [1,2,3,4] B = [2,3,4,5] C = A*B = [2,6,12,20] I can\'t even figure out the code, I\'ve tried doing so element by element but this seems too messy of a solution for me, any ideas? 回答1: "Zipping" the two arrays gives a sequence of tuples (a_i, b_i) which can then be multiplied element-wise: let A = [1,2,3,4] let B = [2,3,4,5] let C = zip(A, B).map { $0 * $1 } print(C) /

How to perform element-wise multiplication of two lists?

时光总嘲笑我的痴心妄想 提交于 2019-11-26 11:11:38
I want to perform an element wise multiplication, to multiply two lists together by value in Python, like we can do it in Matlab. This is how I would do it in Matlab. a = [1,2,3,4] b = [2,3,4,5] a .* b = [2, 6, 12, 20] A list comprehension would give 16 list entries, for every combination x * y of x from a and y from b . Unsure of how to map this. If anyone is interested why, I have a dataset, and want to multiply it by Numpy.linspace(1.0, 0.5, num=len(dataset)) =) . Use a list comprehension mixed with zip() :. [a*b for a,b in zip(lista,listb)] Since you're already using numpy , it makes sense

How to perform element-wise multiplication of two lists?

不问归期 提交于 2019-11-26 02:06:51
问题 I want to perform an element wise multiplication, to multiply two lists together by value in Python, like we can do it in Matlab. This is how I would do it in Matlab. a = [1,2,3,4] b = [2,3,4,5] a .* b = [2, 6, 12, 20] A list comprehension would give 16 list entries, for every combination x * y of x from a and y from b . Unsure of how to map this. If anyone is interested why, I have a dataset, and want to multiply it by Numpy.linspace(1.0, 0.5, num=len(dataset)) =) . 回答1: Use a list