title: How to compute volume of 10-Dimentional sphere with Monte-Carlo-Method in Python?
body: <p>I am trying to compute the volume of a 10 dimensional sphere with python, but my computation doesn't work. </p>
  
  <p>Here is my code: </p>
  
  <pre><code>def nSphereVolume(dim,iter):
      i = 0
      j = 0
      r = 0
      total0 = 0
      total1 = 0
  
      while (i &lt; iter):
          total0 = 0;
          while (j &lt; dim):
              r = 2.0*np.random.uniform(0,1,iter) - 1.0
  
              total0 += r*r
              j += 1
  
          if (total0 &lt; 1):
              total1 += 1
          i += 1
  
      return np.pow(2.0,dim)*(total1/iter)
  
  nSphereVolume(10,1000)
  </code></pre>
  
  <p>Here the error:</p>
  
  <pre><code>---------------------------------------------------------------------------
  ValueError                                Traceback (most recent call last)
  &lt;ipython-input-253-44104dc9a692&gt; in &lt;module&gt;()
       20     return np.pow(2.0,dim)*(total1/iter)
       21 
  ---&gt; 22 nSphereVolume(10,1000)
  
  &lt;ipython-input-253-44104dc9a692&gt; in nSphereVolume(dim, iter)
       14             j += 1
       15 
  ---&gt; 16         if (total0 &lt; 1):
       17             total1 += 1
       18         i += 1
  
  ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
  </code></pre>
  
  <p>Could someone who knows this algorithm try to run it and tell me what would be corret to implement, to get the volume of this 10-dim sphere? Thanks! </p>