multiplication

Multiply and replace values in data frame according to condition in R

笑着哭i 提交于 2021-02-17 02:52:08
问题 I'm new to R and I've been trying to multiply and replace certain values in my data frame with no success. Basically, what I want to do is that when a value from my df (any column) is 0 < x < 1, multiplicate it by 10 and then replace that value with the result of this equation. A glimpse to my df just in case... 'data.frame': 404 obs. of 15 variables: $ D3: num 16.1 17.1 16.1 16.1 17.2 ... $ TH : num 9.9 8.6 9.7 7.7 7.6 7.6 8.7 9.8 9.8 7.7 ... $ D2 : num 33.3 29.3 30.3 29.3 33.3 ... $ D1 :

How to simply multiply two columns of a dataframe? [duplicate]

别说谁变了你拦得住时间么 提交于 2021-02-10 04:36:06
问题 This question already has answers here : Efficient multiplication of columns in a data frame (4 answers) Closed 3 years ago . My input is a<-c(1,2,3,4) b<-c(1,2,4,8) df<-data.frame(cbind(a,b)) My output should be a<-c(1,2,3,4) b<-c(1,2,4,8) d<-c(1,4,12,32) df<-data.frame(cbind(a,b,c)) can i simply say df$a * df$b please help. I am getting an issue with duplication. they are getting multiplied in matrix form and there is also issue with different length columns. 回答1: In Base R: df$c <- df$a *

Little to big endian using multiplication and division - MIPS assembly

吃可爱长大的小学妹 提交于 2021-02-08 09:50:30
问题 I have a school assignment that requires me to convert a word from little endian to big endian in three different ways. One of them is by using multiplication and division. I know that shifting to the left multiplies the number by 2 but i still cant figure out how to utilise that. Here is me doing it using rotate. Can someone help me step on this and do it with division and multiplication? .data .text .globl main main: li $t0,0x11223344 #number to be converted in t0 rol $t1,$t0,8 li $t2

How to design a 64 x 64 bit array multiplier in Verilog?

三世轮回 提交于 2021-02-07 12:38:22
问题 I know how to design a 4x4 array multiplier , but if I follow the same logic , the coding becomes tedious. 4 x 4 - 16 partial products 64 x 64 - 4096 partial products. Along with 8 full adders and 4 half adders, How many full adders and half adders do I need for 64 x 64 bit. How do I reduce the number of Partial products? Is there any simple way to solve this ? 回答1: Whenever tediously coding a repetitive pattern you should use a generate statement instead: module array_multiplier(a, b, y);

multiply two consecutive times in assembly language program

允我心安 提交于 2021-02-05 12:32:50
问题 I am using 8086 emulator and DOSBOX and MASM. I know that when we multiply 8-bit with 8-bit, answer will be of 16-bit. al*(8-bit)=ax And when we multiply 16-bit with 16-bit,answer will of 32-bit. ax*(16-bit)=dx & ax But if the answer is in (dx & ax) and I want to multiply 8-bit or 16-bit number then it will simply perform with ax But I needed to multiply a number with answer in (dx & ax) . So how to overcome this problem? I need solve this situation for the factorial program. Where I am

Java 8 matrix * vector multiplication

最后都变了- 提交于 2021-02-04 17:38:29
问题 I'm wondering if there is a more condensed way of doing the following in Java 8 with streams: public static double[] multiply(double[][] matrix, double[] vector) { int rows = matrix.length; int columns = matrix[0].length; double[] result = new double[rows]; for (int row = 0; row < rows; row++) { double sum = 0; for (int column = 0; column < columns; column++) { sum += matrix[row][column] * vector[column]; } result[row] = sum; } return result; } Making an Edit. I received a very good answer,

fortran matrix vector multiplication optimization

為{幸葍}努か 提交于 2021-01-29 16:30:58
问题 I tried to measure the difference of different matrix-vector-multiplication schemes in Fortran. I have actually written the following code: http://pastebin.com/dmKXdnX6 The 'optimized version' is meant to respect the memory layout of the matrix, by swapping the loops to access the matrix-elements. The provided code should compile with gfortran and it runs with the following rather surprising results: Vectors match! Calculations are OK. Optimized time: 0.34133333333333332 Naive time: 1

Number of digits after multiplication, dividing

一世执手 提交于 2021-01-29 07:18:16
问题 I have two numbers X and Y , i don't know their values but i know that the maximal number of digits that can contain X is 10 (for example) and for Y is 3 (for example) I need to know the maximal number of digits of Z that equals to X * Y . Same for Z = X / Y 回答1: If X can have at most n digits and Y can have at most m digits, then X < 10 ^ n and Y < 10 ^ m This means that X * Y < 10 ^ n * 10 ^ m = 10 ^ (n + m) In other words, X * Y can have at most n + m digits. With division, we need to take

Can't wrap my head around this this recursion example [duplicate]

六月ゝ 毕业季﹏ 提交于 2021-01-07 02:53:58
问题 This question already has answers here : How does this recursion work? (11 answers) Closed 4 days ago . So there is this recursion example in chap 3 of Eloquent JavaScript, it goes like this: Consider this puzzle: by starting from the number 1 and repeatedly either adding 5 or multiplying by 3, an infinite set of numbers can be produced. How would you write a function that, given a number, tries to find a sequence of such additions and multiplications that produces that number? And the given

Can't wrap my head around this this recursion example [duplicate]

风格不统一 提交于 2021-01-07 02:53:12
问题 This question already has answers here : How does this recursion work? (11 answers) Closed 4 days ago . So there is this recursion example in chap 3 of Eloquent JavaScript, it goes like this: Consider this puzzle: by starting from the number 1 and repeatedly either adding 5 or multiplying by 3, an infinite set of numbers can be produced. How would you write a function that, given a number, tries to find a sequence of such additions and multiplications that produces that number? And the given