title: How do you loop through an array, perform calculations on the arrays and plot the results?
body: <p>I am very new to programming, and would appreciate some assistance with my program.  I'm trying to read in arrays through a for loop, do some calculations on them and plot the result on a 3D graph, but it gives me the error:</p>
  
  <pre><code>IndexError: index 753 is out of bounds for axis 0 with size 753
  </code></pre>
  
  <p>Here's the code:</p>
  
  <pre><code>from mpl_toolkits.mplot3d import Axes3D 
  import matplotlib.pyplot as plt
  import numpy as np
  import math
  from itertools import product, combinations
  from numpy import *
  fig = plt.figure()
  ax = fig.gca(projection='3d')
  ax.set_aspect("equal")
  
  ra_day = loadtxt("RA Days.txt")  
  ra_minute = loadtxt("RA Minutes.txt")
  ra_second = loadtxt("RA Seconds.txt")
  ra = ra_day + (ra_minute/60) + (ra_second/3600)  
  
  dec_day = loadtxt("DEC Days.txt")  
  dec_minute = loadtxt("DEC Minutes.txt")
  dec_second = loadtxt("DEC Seconds.txt")
  dec = dec_day + (dec_minute/60) + (dec_second/3600)  
  
  dist = loadtxt("Distance.txt") 
  
  for i in range(len(ra)):
      x = math.cos(ra[i]) * (dist[i] * math.cos(dec[i]))
      y = math.sin(ra[i]) * (dist[i] * math.cos(dec[i]))
      z = dist * math.sin(dec[i])
  
  ax.scatter([0],[0],[0],color="b",s=100)
  ax.scatter([x],[y],[z],color="k",s=100)
  
  plt.show()
  </code></pre>