Modification of array using NumPy

We have the flexibility to modify individual elements within an array without altering the entire array..

Result:

Explanation:

  1. import numpy as np: This line imports the NumPy library under the alias np.
  2. frame = np.array([[0,0,0],[0,0,0],[0,0,0]]): This line creates a 3×3 NumPy array filled with zeros, just like before. frame is initialized as a 3×3 array filled with zeros.
  3. frame[1,2]=1: This line modifies one element of the frame array. It sets the element at the second row (index 1) and the third column (index 2) to the value 1. In Python indexing, arrays are zero-indexed, so the second row is indexed as 1, and the third column is indexed as 2.
  4. print(frame): This line prints the contents of the modified frame array to the console. Since we changed one element to 1,

Leave a comment

Your email address will not be published. Required fields are marked *