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')`)
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)

```