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
-1
votes
3 answers

Merging sub-arrays of a merge sort

I found the following code from geeks for geeks and I don't seem to understand how the sub-arrays are being sorted(i.e. when we sort the left sub-array and then the right sub-array and then, merge both left and right sub-arrays, how come we don't…
Solruhama
  • 101
  • 7
-1
votes
2 answers

Indexing by row name

Can someone please help me with this. I want to call rows by name, so I used set_index on the 1st column in the dataframe to index the rows by name instead of using integers for indexing. # Set 'Name' column as index on a Dataframe df1 =…
user6688
  • 31
  • 7
-1
votes
1 answer

how can i use fillna(inplace=True) in for loop?

df = pd.read_csv('IMDB-Movie-Data.csv') dp = df.groupby('Director')['Revenue (Millions)'].mean() for i in dp.index: df.loc[df['Director']==i,'Revenue (Millions)'].fillna(dp[i],inplace = True) sorry for bad English dp is Revenue column's mean…
HLEE
  • 1
  • 1
-1
votes
1 answer

Convert any base to decimal using Horner's recursively

I have to write a program converting from any base to decimal using recursion and Horner's scheme. All I can use is: an int method with two parameters like public static int horner (int[] digits, int base){}. I have to implement the method…
Msitake
  • 13
  • 2
-1
votes
1 answer

Linux- Add/Insert in only the secondlast line with a new value keeping original content intact in same file

I need to add/insert a value "new content" on the secondlast line of the same file without deleting any of the lines or content of my file. The condition is that the file content keeps changing and line numbers do not remain fixed. Sample…
Automation Engr
  • 444
  • 2
  • 4
  • 26
-1
votes
1 answer

How to change a variable by reference like Pandas inplace

So I was working with Pandas and I recently came across the inplace argument, which changes the original variable without having to reassign it. Example : df.dropna(inplace=True) instead of df = df.dropna() I want to apply the same mechanism but for…
Amine Messaoudi
  • 2,141
  • 2
  • 20
  • 37
-1
votes
1 answer

In-place methods in subclasses

I am trying to subclass list in order to create an in-place method that updates self with the item-wise sum of itself and a new list. Example: This is how I tried to do it: class RecordBook(list): def accumulate(self, new_values): self =…
Ma0
  • 15,057
  • 4
  • 35
  • 65
-1
votes
2 answers

Is this implementation of quick sort considered "in place"?

This is an implementation of quick sort which is easier for me to understand than the others I found. Although, this implementation does not appear to be "in place" as quick sort is apparently supposed to be. I'm thinking it isn't "in place" because…
-1
votes
1 answer

Reverse the string (IN PLACE) in python

I want to know how to reverse a string in python without creating a new one. I can't seem to get it.
Khizar Khan
  • 1
  • 1
  • 1
-1
votes
2 answers

Opencv: How to use rectangle() function to draw a rectangle on a COPY of an image rather than the original image?

this is what I am trying to accomplish. I have some images with multiple bounding boxes associated with each image. I want to load an image, draw box1 on image, and save the new image as image_1. Then I want to draw box2 on image, and save it as…
Terry Martin
  • 529
  • 8
  • 20
-1
votes
1 answer

Revert singly-linked-list iterative inplace

I am learning for an upcoming exam and we have the following exercise: Revert a singly-linked-list by the following rules: Iterative Inplace no Constructors last Element always has null as next Element I already found a few solutions and have come…
lukstru
  • 138
  • 1
  • 9
-1
votes
2 answers

How can I use an if-else condition inside a list comprehension to overwrite an existing list?

I'm trying to multiply numbers greater than 3 by two, and subtract one from everything else. However, nothing happens to the list. This is my code: lst = [1,2,3,4,5,6,7,8,9,10] print (lst) [x*2 if x > 3 else x-1 for x in lst] print…
-1
votes
3 answers

Sort an IList in place

If I have a List, I can sort it in place using for example myList.Sort((x,y) => x.MyComparisonMethod(y)); If I have an IList, I can sort it into a new list using var sortedIList = unsortedIList.OrderBy(x => x.SortingValue); How can I sort an…
tomsv
  • 7,207
  • 6
  • 55
  • 88
-2
votes
0 answers

Sed in-place modification on Mac OS with variable subtitution

I want to do in place modification in README.md file, but also allow variable substitution. The line that I want to modify starts with "[![Data Layer]...". I have tried: sed -i "" "s|\[!\[Data Layer\].*|[![Data…
nika
  • 1
  • 2
-2
votes
3 answers

Remove element from list and print new list in the same statement

I am using the .remove() function to remove an element from a list and then I want to use directly this new list into another function e.g. the print() function. When I am doing this then I get the following: print([1, 2, 3]) # [1, 2, 3] print([1,…
Outcast
  • 4,967
  • 5
  • 44
  • 99
1 2 3
25
26