Doubt Dhanabalu Doubt Dhanabalu - 1 year ago 84
Python Question

How to replace a value in array in numpy python

I have a very basic question in numpy arrays:

My array looks something like this:

Array = [["id1", "1.0"],["id2", "0.0"]]

I want to read the second element of the array and replace with an another character. Its like

for i in range(0,len(array)):
if array[i] == "0.0":
array[i] = "ClassA"
array[i] = "ClassB"

How to achieve this. I am not able to read "0.0" or "1.0" correctly.
Please help.

Answer Source

You have two arrays inside an array. The below code should work:

array = [["id1", "1.0"],["id2", "0.0"]]

for i in range(0,len(array)):
    if array[i][1] == "0.0":
        array[i][1] = "ClassA"
        array[i][1] = "ClassB"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download