Questions tagged [in-place]

Use this tag on questions about algorithms that modify the data in-place, as opposed to making a copy. For example, in-place sorting, in-place merge, etc.

Use this tag on questions about algorithms that modify the data in-place, as opposed to making a copy. For example, in-place , in-place , etc.

379 questions
41
votes
6 answers

Python a &= b meaning?

What does the &= operator mean in Python, and can you give me a working example? I am trying to understand the __iand__ operator. I just don't know what &= means and have looked online but couldn't find it.
Aaron Lelevier
  • 19,850
  • 11
  • 76
  • 111
40
votes
4 answers

Is Quicksort in-place or not?

So the space efficiency of Quicksort is O(log(n)). This is the space required to maintain the call stack. Now, according to the Wikipedia page on Quicksort, this qualifies as an in-place algorithm, as the algorithm is just swapping elements within…
40
votes
4 answers

Numpy modify array in place?

I have the following code which is attempting to normalize the values of an m x n array (It will be used as input to a neural network, where m is the number of training examples and n is the number of features). However, when I inspect the array in…
User
  • 62,498
  • 72
  • 186
  • 247
38
votes
9 answers

In-place processing with grep

I've got a script that calls grep to process a text file. Currently I am doing something like this. $ grep 'SomeRegEx' myfile.txt > myfile.txt.temp $ mv myfile.txt.temp myfile.txt I'm wondering if there is any way to do in-place processing, as in…
Daniel Standage
  • 8,136
  • 19
  • 69
  • 116
34
votes
1 answer

Why aren't Pandas operations in-place?

Pandas operations usually create a copy of the original dataframe. As some answers on SO point out, even when using inplace=True, a lot of operations still create a copy to operate on. Now, I think I'd be called a madman if I told my colleagues that…
Luiz Martins
  • 1,644
  • 10
  • 24
31
votes
4 answers

In-place sort_values in pandas what does it exactly mean?

Maybe a very naive question, but I am stuck in this: pandas.Series has a method sort_values and there is an option to do it "in place" or not. I have Googled for it a while, but I am not very clear about it. It seems that this thing is assumed to be…
Karel Macek
  • 1,119
  • 2
  • 11
  • 24
31
votes
6 answers

What is an in-place constructor in C++?

Possible Duplicate: C++'s “placement new” What is an in-place constructor in C++? e.g. Datatype *x = new(y) Datatype();
Akhil
  • 2,269
  • 6
  • 32
  • 39
30
votes
4 answers

In-place modification of Python lists

I am trying to perform in-place modification of a list of list on the level of the primary list. However, when I try to modify the iterating variable (row in the example below), it appears to create a new pointer to it rather than modifying…
Alexander
  • 908
  • 1
  • 11
  • 14
30
votes
4 answers

Converting an empty string to nil in place?

I'm looking for a way to convert an empty string to nil in place using Ruby. If I end up with a string that is empty spaces I can do " ".strip! This will give me the empty string "". What I would like to be able to do is something like this. "…
bigtunacan
  • 4,873
  • 8
  • 40
  • 73
25
votes
7 answers

How to master in-place array modification algorithms?

I am preparing for a software job interview, and I am having trouble with in-place array modifications. For example, in the out-shuffle problem you interleave two halves of an array so that 1 2 3 4 5 6 7 8 would become 1 5 2 6 3 7 4 8. This question…
Frank
  • 269
  • 3
  • 3
25
votes
6 answers

How do you append an element to a list in place in Prolog?

If I have a list in Prolog such as X = [1, 2, 3, 4], how do I add the element 5 to the end of the list to have X = [1, 2, 3, 4, 5]? The append function needs two lists, ie append(A,B,C) to get A and B concatenated to the list C. I can do this…
No One in Particular
  • 2,846
  • 4
  • 27
  • 32
23
votes
1 answer

numpy array, difference between a /= x vs. a = a / x

I'm using python 2.7.3, when I execute the following piece of code: import numpy as np a = np.array([[1,2,3],[4,5,6]]) a = a / float(2**16 - 1) print a This will result in he following output: >> array([[1.52590219e-05, 3.05180438e-05,…
Gio
  • 3,242
  • 1
  • 25
  • 53
21
votes
2 answers

Numpy passing input array as `out` argument to ufunc

Is it generally safe to provide the input array as the optional out argument to a ufunc in numpy, provided the type is correct? For example, I have verified that the following works: >>> import numpy as np >>> arr = np.array([1.2, 3.4, 4.5]) >>>…
Mad Physicist
  • 107,652
  • 25
  • 181
  • 264
21
votes
4 answers

In-place replacement of all occurrences of an element in a list in python

Assume I have a list: myl = [1, 2, 3, 4, 5, 4, 4, 4, 6] What is the most efficient and simplest pythonic way of in-place (double emphasis) replacement of all occurrences of 4 with 44? I'm also curious as to why there isn't a standard way of doing…
lifebalance
  • 1,846
  • 3
  • 25
  • 57
21
votes
7 answers

What are the best options for Rich Text Editing in Rails?

I'd like to use Rich Text Editing in place on forms in order to let admins change instructions. What are the best options for doing this? [To be more clear - the admins are non-technical but may want to control some formatting without using markup…
srboisvert
  • 12,679
  • 15
  • 63
  • 87
1
2
3
25 26