Same Python code , different performance
<p>I wrote this code in Python and there's something driving me crazy. The same code when I put in function, give me different results!! How that can be? This is the code in the main and the same code in a function</p>

<pre><code>def iterateTesting(k):
    Accuracy = []
    for t in range(0,10):
        train_data,test_data = shuffleAndSplit(data)
        acurracy = test(train_data,test_data,k)
        Accuracy.append(acurracy)
    print ('{0:.2f}% , {1:.2f}').format(np.mean(Accuracy),np.std(Accuracy))

data = getData("d.data")


train_data,test_data = shuffleAndSplit(data)
Accuracy = []
for t in range(0,10):
    train_data,test_data = shuffleAndSplit(data)
    acurracy = test(train_data,test_data,1)
    Accuracy.append(acurracy)
print ('{0:.2f}% , {1:.2f}').format(np.mean(Accuracy),np.std(Accuracy))
iterateTesting(1)
</code></pre>

<p>I get around 55% from the function and 65% from the main everytime I run the code. I'm calling the same functions and using the same data. I will really appreciate if someone clarify. Thanks</p>

<p>Problem solved by defining training and testing data as global variables in my function</p>

python python-2.7 numpy scikit-learn kdtree