Questions tagged [shift]

Questions related to the usage of the right and/or left shift key on the keyboard. For questions regarding bitwise shift operations use [bit-shift]

Questions related to the usage of the right and/or left Shift key on the keyboard. For questions regarding bitwise shift operations use

1054 questions
172
votes
13 answers

Move column by name to front of table in pandas

Here is my df: Net Upper Lower Mid Zsore Answer option More than once a day 0% 0.22% -0.12% 2 65 Once a day 0% 0.32% -0.19% …
Boosted_d16
  • 13,340
  • 35
  • 98
  • 158
64
votes
16 answers

Java, Shifting Elements in an Array

I have an array of objects in Java, and I am trying to pull one element to the top and shift the rest down by one. Assume I have an array of size 10, and I am trying to pull the fifth element. The fifth element goes into position 0 and all elements…
darksky
  • 20,411
  • 61
  • 165
  • 254
58
votes
4 answers

Comparing previous row values in Pandas DataFrame

import pandas as pd data={'col1':[1,3,3,1,2,3,2,2]} df=pd.DataFrame(data,columns=['col1']) print df col1 0 1 1 3 2 3 3 1 4 2 5 3 …
jth359
  • 779
  • 1
  • 8
  • 10
48
votes
6 answers

Disable New Line in Textarea when Pressed ENTER

I am calling a function whenever someone press enter in the textarea. Now I want to disable new line or break when enter is pressed. So new line should work when shift+enter is pressed. In that case, the function should not be called. Here is…
Hassan Sardar
  • 4,413
  • 17
  • 56
  • 92
46
votes
5 answers

c get nth byte of integer

I know you can get the first byte by using int x = number & ((1<<8)-1); or int x = number & 0xFF; But I don't know how to get the nth byte of an integer. For example, 1234 is 00000000 00000000 00000100 11010010 as 32bit integer How can I get all…
Kamran224
  • 1,584
  • 7
  • 20
  • 33
43
votes
5 answers

IntelliJ Shift Shift Shortcut in Visual Studio (Global Search)

After doing some Java I fell in love with some of IntelliJ's features. Especially the keyboard shortcut SHIFT +SHIFT which lets you jump to any other file. This is a huge time savesaver. Now that I'm back in VS I really miss that feature when I'm…
AlexVPerl
  • 7,652
  • 8
  • 51
  • 83
31
votes
3 answers

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

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…
Alex H Hadik
  • 774
  • 2
  • 7
  • 16
28
votes
8 answers

Is 'shift' evil for processing Perl subroutine parameters?

I'm frequently using shift to unpack function parameters: sub my_sub { my $self = shift; my $params = shift; .... } However, many on my colleagues are preaching that shift is actually evil. Could you explain why I should prefer sub…
Nikolai Prokoschenko
  • 8,465
  • 11
  • 58
  • 97
26
votes
15 answers

Rotate array elements to the left (move first element to last and re-index)

Is it possible to easily 'rotate' an array in PHP? Like this: 1, 2, 3, 4 -> 2, 3 ,4 ,1 Is there some kind of built-in PHP function for this?
Dylan
  • 9,129
  • 20
  • 96
  • 153
22
votes
5 answers

How do I shift an array of items up by 4 places in Javascript

How do I shift an array of items up by 4 places in Javascript? I have the following string array: var array1 = ["t0","t1","t2","t3","t4","t5"]; I need a function convert "array1" to result in: // Note how "t0" moves to the fourth position for…
Darryl Hebbes
  • 998
  • 1
  • 9
  • 15
21
votes
2 answers

Is left-shifting a signed integer undefined behavior in C++03?

According to C++03, 5.8/2, left-shifting is defined as follows: The value of E1 << E2 is E1 (interpreted as a bit pattern) left-shifted E2 bit positions; vacated bits are zero-filled. If E1 has an unsigned type, the value of the result is E1…
sharptooth
  • 167,383
  • 100
  • 513
  • 979
21
votes
1 answer

Shuffle a List in Scala

I have question to for shuffle list in scala using scala.util.Random. For example I have val a = cyan val b = magenta val c = yellow val d = key val color = Random.shuffle.List(a,b,c,d).toString //but it doesn't work ;( so I want the val color to…
Deden Bangkit
  • 598
  • 1
  • 5
  • 19
20
votes
5 answers

Optimization levels in gcc changing c program behaviour

I'm seeing behaviour I don't expect when compiling this code with different optimization levels in gcc. The function test should fill a 64 bit unsigned integer with ones, shift them shift_size bits to the left, and return the 32 low bits as a 32 bit…
user1142769
  • 201
  • 1
  • 4
19
votes
1 answer

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

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] +…
jayc
  • 329
  • 1
  • 8
19
votes
2 answers

how to do circular shift in numpy

I have a numpy array, for example a = np.arange(10) how can I move the first n elements to the end of the array? I found this roll function but it seems like it only does the opposite, which shifts the last n elements to the beginning.
LWZ
  • 11,670
  • 22
  • 61
  • 79
1
2 3
70 71