SoFunction
Updated on 2024-10-29

python numpy add, delete, and check ndarry by index

existnumpyhit the nail on the headndarryis an array, so index is the position subscript.Note that the subscripts start at 0

  • Add: use () for insertion and () for end additions
  • Delete: requires the use of ()
  • Modify: Specify subscripts directly
  • Find: Specify subscripts directly

Sample code:

import numpy as np

if __name__ == '__main__':
    array = (["a", "b", "c", "d", "e", "f", "g"])
    # Insert into the specified index
    insert_array = (array, 1, [11, 12])
    print("Insert:", insert_array)
    
    # Delete the specified index
    delete_array = (array, [1, 3, 5])
    print("Delete:", delete_array)
    
    # Modify
    array[0] = 999
    print("Modify:", array)
    
    # Find
    search_array = array[[1, 2, 3, 4]]
    print("Find:", search_array)

Results:

Insert: ['a' '1' '1' 'b' 'c' 'd' 'e' 'f' 'g']
Delete: ['a' 'c' 'e' 'g']
Modified: ['9' 'b' 'c' 'd' 'e' 'f' 'g']
Find: ['b' 'c' 'd' 'e']

to this article on python numpy ndarry in accordance with the index add, delete and check the article is introduced to this, more related python numpy ndarry in accordance with the index add, delete and check the contents of the search for my previous articles or continue to browse the following related articles I hope you will support me in the future more!