np.ndarray with Periodic Boundary conditions
<h2>Problem</h2>
<p>To impose <code>np.ndarray</code> periodic boundary conditions as laid out below</p>
<h2>Details</h2>
<ul>
<li>Wrap the indexing of a python <code>np.ndarray</code> around the boundaries in <code>n</code>-dimensions</li>
<li>This is a periodic boundary condition forming an <code>n</code>-dimensional torus</li>
<li>Wrapping <strong>only</strong> occurs in the case that the value returned is <strong>scalar</strong> (a single point).</li>
<li><strong>Slices</strong> will be treated as normal and will <strong>not</strong> be wrapped</li>
</ul>
<p>An example and counterexample are given below:</p>
<pre><code>a = np.arange(27).reshape(3,3,3)
b = Periodic_Lattice(a) # A theoretical class
    
# example: returning a scalar that shouldn't be accessible
print b[3,3,3] == b[0,0,0] # returns a scalar so invokes wrapping condition 
try: a[3,3,3] # the value is out of bounds in the original np.ndarray
except: print 'error'

# counter example: returning a slice
try: b[3,3] # this returns a slice and so shouldn't invoke the wrap
except: print 'error'
</code></pre>
<p>which should give the output:</p>
<pre><code>True
error
error
</code></pre>
<p>I anticipate that I should be overloading <code>__getitem__</code> and <code>__setitem__</code> within <code>np.ndarray</code> but how to proceed with this is not entirely clear and there are many implementations on SO that fail for many test cases.</p>