Updating a Null Vector

Write a NumPy program to create a null vector of size 10 and update the sixth value to 11. Return the updated vector.

Example 1:

Input: None 
Output: array([0., 0., 0., 0., 0., 11., 0., 0., 0., 0.])

Example 2:

Input: None 
Output: array([0., 0., 0., 0., 0., 11., 0., 0., 0., 0.])

You can use np.zeros() function to create a null vector. Remember, array indexing in Python starts from 0.

import numpy as np

def update_vector():
    vector = np.zeros(10)
    vector[5] = 11
    return vector

print(update_vector())

 

© Let’s Data Science

LOGIN

Unlock AI & Data Science treasures. Log in!