-1

I am using the NumPy array to store the string. However, I want to delete the index from 0 to n in the string. I tried multiple approaches but did not get the proper result. Can anyone help me with this?

for eg, if the length of the string is 1929 and want to delete index 1 to 1000 from the string.

arr=np.array([])
print(type(arr))
    

Can anyone help me with this?

Yevhen Kuzmovych
  • 10,940
  • 7
  • 28
  • 48
  • 1
    We need a small example, and one or more of the 'multiple' failures. – hpaulj Jun 07 '22 at 14:31
  • Since you didn't provide an example, much less code and desired results, the answers made different assumptions about what you are starting with. – hpaulj Jun 07 '22 at 15:44
  • This is clearly explained here: https://stackoverflow.com/questions/509211/understanding-slicing – wovano Jun 07 '22 at 18:24

1 Answers1

-1

Slicing an array in Python is quite straightforward, the syntax is variable[starting_index:ending_index]. You can leave either index blank to basically get "the rest" of the array

# starting array
arr1 = ["h", "e", "l", "l", "o", " ", "w", "o", "r", "l", "d"]
print(arr1)

# everything after 6th element
arr2 = arr1[6:]
print(arr2)

# elements 6th, 7th and 8th only
arr3 = arr1[6:9]
print(arr3)

result:

['h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd']
['w', 'o', 'r', 'l', 'd']
['w', 'o', 'r']
KrisRogo
  • 120
  • 8
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Ethan Jun 07 '22 at 12:00