title: Create a matrix of alternating zeroes and random numbers?
body: <p>I'm trying to write some code that will create a matrix of alternating 1/-1 and 0 i.e:</p>
  
  <pre><code>[-1  0 -1  0  1  0  1  0 -1  0]
  [ 0  1  0 -1  0  1  0 -1  0  1]
  [ 1  0  1  0 -1  0 -1  0 -1  0]
  [ 0  1  0 -1  0 -1  0 -1  0  1]
  [ 1  0  1  0  1  0  1  0  1  0]
  </code></pre>
  
  <p>I've created a class that generates a matrix of zeroes and appends it with 1 or -1 and I have tried messing with my for loop and slicing my matrix but I can't seem to generate the matrix I'd like above. I have an intermediate level of python knowledge so I appreciate that a solution to my problem using the code I've created might not be particularly elegant but any help would be greatly appreciated.</p>
  
  <pre><code>import numpy as np
  import scipy as sp
  import matplotlib.pyplot as plt
  import random
  
  
  #constants
  N = 10 #dimensions of matrix
  
  
  class initial_lattice: 
      def __init__(self,N):   #create initial matrix of size NxN
          self.N=N
          self.matrix_lattice()
  
      def matrix_lattice(self):
          self.lattice = np.zeros((N,N), dtype=int) #creates initial matrix of zeroes
          for x in range(0,N):    
              for y in range(0,N):
                  self.lattice[x,y]=random.choice([1,-1]) #randomly chooses values of 1 and -1 and appends matrix
  
  lattice1=initial_lattice(N) 
  
  
  print lattice1.lattice
  </code></pre>