Question: I want to know if an array is already defined somewhere before in the code.
Something like `a.exist()` gives True if it exists and False if it doesn't. 

I tried `a.size:`, but if the array doesn't exist yet, it gives an error message, which I want to avoid.

The situation demanding this happened in a loop, if you are wondering.

Answer: 
You'll need to use a try/except block:

```
try:
    _ = a.shape
except NameError:
    print('a does not exist.')
except AttributeError:
    print('a does not have a shape property.')

```

As @padraic points out, this really shouldn't occur in the first place. It is best to initialize your variables (e.g. `a = None`) and then check that they have been set (e.g. `if a: print('a is set') else: print('a has not been set')`)
In case you want to be sure that `a` is a `numpy` array and not any other type that may have a `size` variable or method, you can check the type warped in a try block to handle the exception in case the variable is not defined. This way you go ahead only if `a` exists and is a `numpy` array.

```
import numpy as np
a = np.array([1,2])
try:
    if isinstance(b,np.ndarray):
        print("TRUE")
except NameError:
    print("FALSE")

```