shift

data.table | faster row-wise recursive update within group

非 Y 不嫁゛ 提交于 2020-07-04 05:40:05
问题 I have to do the following recursive row-by-row operation to obtain z : myfun = function (xb, a, b) { z = NULL for (t in 1:length(xb)) { if (t >= 2) { a[t] = b[t-1] + xb[t] } z[t] = rnorm(1, mean = a[t]) b[t] = a[t] + z[t] } return(z) } set.seed(1) n_smpl = 1e6 ni = 5 id = rep(1:n_smpl, each = ni) smpl = data.table(id) smpl[, time := 1:.N, by = id] a_init = 1; b_init = 1 smpl[, ':=' (a = a_init, b = b_init)] smpl[, xb := (1:.N)*id, by = id] smpl[, z := myfun(xb, a, b), by = id] I would like

Pandas delete and shift cells in a column basis multiple conditions

依然范特西╮ 提交于 2020-06-16 04:11:15
问题 I have a situation where I would want to delete and shift cells in a pandas data frame basis some conditions. My data frame looks like this : Value_1 ID_1 Value_2 ID_2 Value_3 ID_3 A 1 D 1 G 1 B 1 E 2 H 1 C 1 F 2 I 3 C 1 F 2 H 1 Now I want to compare the following conditions: ID_2 and ID_3 should always be less than or equal to ID_1. If anyone of them is greater than ID_1 then that cell should be deleted and shifted with the next column cell The output should look like the following : Value_1

Shifting 64 bit value left by 64 bits in C++ giving weird results [duplicate]

那年仲夏 提交于 2020-05-07 19:28:23
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: 64bit shift problem I'm using Visual Studio 2012 on Windows 8 64-bit, targeting x64 in debug mode, using an AMD Phenom II. So Basically... uint64_t Foo = 0xFFFFFFFFFFFFFFFF << 64;//Foo is now 0x0000000000000000 uint64_t Derp = 64; uint64_t Bar = 0xFFFFFFFFFFFFFFFF << Derp;//Foo is now 0xFFFFFFFFFFFFFFFF Using a lower value such as 63 restores normal behavior. Why is this happening and how can I get around it?

Can anyone explain why '>>2' shift means 'divided by 4' in C codes?

∥☆過路亽.° 提交于 2020-03-13 03:47:54
问题 I know and understand the result. For example: <br> 7 (decimal) = 00000111 (binary) <br> and 7 >> 2 = 00000001 (binary) <br> 00000001 (binary) is same as 7 / 4 = 1 <br> So 7 >> 2 = 7 / 4 <br> <br> But I'd like to know how this logic is created. Can anyone elaborate on this logic ? (Maybe it's just popped up in a genius head ?) And is there any other similar logics like this ? 回答1: It didn't "pop-up" in a genius' head. Right shifting binary numbers would divide a number by 2 and left shifting

Can anyone explain why '>>2' shift means 'divided by 4' in C codes?

点点圈 提交于 2020-03-13 03:45:56
问题 I know and understand the result. For example: <br> 7 (decimal) = 00000111 (binary) <br> and 7 >> 2 = 00000001 (binary) <br> 00000001 (binary) is same as 7 / 4 = 1 <br> So 7 >> 2 = 7 / 4 <br> <br> But I'd like to know how this logic is created. Can anyone elaborate on this logic ? (Maybe it's just popped up in a genius head ?) And is there any other similar logics like this ? 回答1: It didn't "pop-up" in a genius' head. Right shifting binary numbers would divide a number by 2 and left shifting

Can anyone explain why '>>2' shift means 'divided by 4' in C codes?

家住魔仙堡 提交于 2020-03-13 03:45:31
问题 I know and understand the result. For example: <br> 7 (decimal) = 00000111 (binary) <br> and 7 >> 2 = 00000001 (binary) <br> 00000001 (binary) is same as 7 / 4 = 1 <br> So 7 >> 2 = 7 / 4 <br> <br> But I'd like to know how this logic is created. Can anyone elaborate on this logic ? (Maybe it's just popped up in a genius head ?) And is there any other similar logics like this ? 回答1: It didn't "pop-up" in a genius' head. Right shifting binary numbers would divide a number by 2 and left shifting

Can anyone explain why '>>2' shift means 'divided by 4' in C codes?

老子叫甜甜 提交于 2020-03-13 03:45:26
问题 I know and understand the result. For example: <br> 7 (decimal) = 00000111 (binary) <br> and 7 >> 2 = 00000001 (binary) <br> 00000001 (binary) is same as 7 / 4 = 1 <br> So 7 >> 2 = 7 / 4 <br> <br> But I'd like to know how this logic is created. Can anyone elaborate on this logic ? (Maybe it's just popped up in a genius head ?) And is there any other similar logics like this ? 回答1: It didn't "pop-up" in a genius' head. Right shifting binary numbers would divide a number by 2 and left shifting

Compute winning streak with pandas

空扰寡人 提交于 2020-01-13 18:10:33
问题 I thought I knew how to do this but I'm pulling my hair out over it. I'm trying to use a function to create a new column. The function looks at the value of the win column in the current row and needs to compare it to the previous number in the win column as the if statements lay out below. The win column will only ever be 0 or 1. import pandas as pd data = pd.DataFrame({'win': [0, 0, 1, 1, 1, 0, 1]}) print (data) win 0 0 1 0 2 1 3 1 4 1 5 0 6 1 def streak(row): win_current_row = row['win']

Design a shift register in VHDL

一世执手 提交于 2020-01-06 14:09:35
问题 I try to design a bch code as a shift register, so I have this schematic: (clickable) And I made a VHDL code in Altera Quartus to design this shift register with loops, the compilation works but it doesn't make the expected result during the simulation in ModelSim (no output). It may have some errors in my code: -- Library declaration LIBRARY IEEE; USE IEEE.std_logic_1164.ALL; USE IEEE.std_logic_arith.ALL; USE IEEE.std_logic_unsigned.ALL; -- Entity declaration ENTITY bchcode_implementation

Can anybody please explain (my $self = shift) in Perl

若如初见. 提交于 2019-12-31 08:28:31
问题 I'm having a really hard time understanding the intersection of OO Perl and my $self = shift; The documentation on these individual elements is great, but none of them that I've found touch on how they work together. I've been using Moose to make modules with attributes, and of course, it's useful to reference a module's attribute within said module. I've been told over and over again to use my $self = shift; within a subroutine to assign the module's attributes to that variable. This makes