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: 
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")

```
Using a `try/except NameError` wrapper is good Python. But initializing the variable to something useful before hand is equally good. I don't think there's much of difference in speed, but the code is more readable.

For example:

```
for i in range(5):
    a += 4

```

will produce a 

```
NameError: name 'a' is not defined

```

which can be trapped with:

```
for i in range(5):
    try:
        a += 4
    except NameError:
        a = np.arange(5)

```

But I could define `a` earlier. `None` is a handy value if I don't know before hand what the first value of `a` should be:

```
a=None
for i in range(5):
   if a is None:
       a=np.arange(5)
   a += 4

```

Another common `numpy` practice is to start with an empty list, and accumulate values there.

```
a = []
for i in range(5):
    a.append(np.ones(4)*i)
a = np.array(a)

```