0

I have a data similar to,

import numpy as np
A = np.array( [['1','2','3'], ['a','3','5']] )

Now I want to identify the cell address of 'a'. I have tried the following code for that purpose,

for i in range(0,2):
    for j in range(0,3):
        if (type(float(A[i,j])) == float):
            print(str(i)+str(j))

since, 'a' can't be converted into floating point it shows the following error.

00

01

02

Traceback (most recent call last):

File "", line 3, in

if (type(float(A[i,j])) == float):

ValueError: could not convert string to float: 'a'

Please help. Thank you in advance.

Brad Solomon
  • 38,521
  • 31
  • 149
  • 235

1 Answers1

1

You can try this

import numpy as np

def is_number(s):
   try:
    int(s)
    return True
   except ValueError:
    return False

A = np.array( [['1','2','3'], ['a','3','5']] )

for i in range(0,2):
    for j in range(0,3):
        if not is_number(A[i][j]):
            print i , j