[Scipy-svn] r4616 - trunk/scipy/cluster/tests

scipy-svn at scipy.org scipy-svn at scipy.org
Fri Aug 8 01:33:12 EDT 2008


Author: jarrod.millman
Date: 2008-08-08 00:33:08 -0500 (Fri, 08 Aug 2008)
New Revision: 4616

Modified:
   trunk/scipy/cluster/tests/test_distance.py
   trunk/scipy/cluster/tests/test_hierarchy.py
   trunk/scipy/cluster/tests/test_vq.py
Log:
cleaning up numpy imports, use numpy.testing


Modified: trunk/scipy/cluster/tests/test_distance.py
===================================================================
--- trunk/scipy/cluster/tests/test_distance.py	2008-08-08 01:30:30 UTC (rev 4615)
+++ trunk/scipy/cluster/tests/test_distance.py	2008-08-08 05:33:08 UTC (rev 4616)
@@ -36,13 +36,12 @@
 
 import sys
 import os.path
-from scipy.testing import *
+
+import numpy as np
+from numpy.testing import *
 from scipy.cluster.hierarchy import squareform, linkage, from_mlab_linkage, numobs_dm, numobs_y, numobs_linkage
 from scipy.cluster.distance import pdist, matching, jaccard, dice, sokalsneath, rogerstanimoto, russellrao, yule
 
-import numpy
-#import math
-
 #from scipy.cluster.hierarchy import pdist, euclidean
 
 _filenames = ["iris.txt",
@@ -68,7 +67,7 @@
               "pdist-chebychev-ml-iris.txt",
               "random-bool-data.txt"]
 
-_tdist = numpy.array([[0,    662,  877,  255,  412,  996],
+_tdist = np.array([[0,    662,  877,  255,  412,  996],
                       [662,  0,    295,  468,  268,  400],
                       [877,  295,  0,    754,  564,  138],
                       [255,  468,  754,  0,    219,  869],
@@ -86,17 +85,17 @@
     for fn in _filenames:
         name = fn.replace(".txt", "").replace("-ml", "")
         fqfn = os.path.join(os.path.dirname(__file__), fn)
-        eo[name] = numpy.loadtxt(open(fqfn))
+        eo[name] = np.loadtxt(open(fqfn))
         #print "%s: %s   %s" % (name, str(eo[name].shape), str(eo[name].dtype))
-    eo['pdist-boolean-inp'] = numpy.bool_(eo['pdist-boolean-inp'])
+    eo['pdist-boolean-inp'] = np.bool_(eo['pdist-boolean-inp'])
 
 load_testing_files()
 
 #print eo.keys()
 
 
-#print numpy.abs(Y_test2 - Y_right).max()
-#print numpy.abs(Y_test1 - Y_right).max()
+#print np.abs(Y_test2 - Y_right).max()
+#print np.abs(Y_test1 - Y_right).max()
 
 class TestPdist(TestCase):
     """
@@ -118,7 +117,7 @@
         "Tests pdist(X, 'euclidean') on random data (float32)."
         eps = 1e-07
         # Get the data: the input matrix and the right output.
-        X = numpy.float32(eo['pdist-double-inp'])
+        X = np.float32(eo['pdist-double-inp'])
         Y_right = eo['pdist-euclidean']
 
         Y_test1 = pdist(X, 'euclidean')
@@ -147,11 +146,11 @@
         "Tests pdist(X, 'euclidean') on the Iris data set. (float32)"
         eps = 1e-06
         # Get the data: the input matrix and the right output.
-        X = numpy.float32(eo['iris'])
+        X = np.float32(eo['iris'])
         Y_right = eo['pdist-euclidean-iris']
 
         Y_test1 = pdist(X, 'euclidean')
-        print numpy.abs(Y_right - Y_test1).max()
+        print np.abs(Y_right - Y_test1).max()
         self.failUnless(within_tol(Y_test1, Y_right, eps))
 
     def test_pdist_euclidean_iris_nonC(self):
@@ -178,7 +177,7 @@
         "Tests pdist(X, 'seuclidean') on random data (float32)."
         eps = 1e-05
         # Get the data: the input matrix and the right output.
-        X = numpy.float32(eo['pdist-double-inp'])
+        X = np.float32(eo['pdist-double-inp'])
         Y_right = eo['pdist-seuclidean']
 
         Y_test1 = pdist(X, 'seuclidean')
@@ -207,7 +206,7 @@
         "Tests pdist(X, 'seuclidean') on the Iris data set (float32)."
         eps = 1e-05
         # Get the data: the input matrix and the right output.
-        X = numpy.float32(eo['iris'])
+        X = np.float32(eo['iris'])
         Y_right = eo['pdist-seuclidean-iris']
 
         Y_test1 = pdist(X, 'seuclidean')
@@ -236,7 +235,7 @@
         "Tests pdist(X, 'cosine') on random data. (float32)"
         eps = 1e-08
         # Get the data: the input matrix and the right output.
-        X = numpy.float32(eo['pdist-double-inp'])
+        X = np.float32(eo['pdist-double-inp'])
         Y_right = eo['pdist-cosine']
 
         Y_test1 = pdist(X, 'cosine')
@@ -260,19 +259,19 @@
 
         Y_test1 = pdist(X, 'cosine')
         self.failUnless(within_tol(Y_test1, Y_right, eps))
-        #print "cosine-iris", numpy.abs(Y_test1 - Y_right).max()
+        #print "cosine-iris", np.abs(Y_test1 - Y_right).max()
 
     def test_pdist_cosine_iris_float32(self):
         "Tests pdist(X, 'cosine') on the Iris data set."
         eps = 1e-07
         # Get the data: the input matrix and the right output.
-        X = numpy.float32(eo['iris'])
+        X = np.float32(eo['iris'])
         Y_right = eo['pdist-cosine-iris']
 
         Y_test1 = pdist(X, 'cosine')
-        print numpy.abs(Y_test1 - Y_right).max()
+        print np.abs(Y_test1 - Y_right).max()
         self.failUnless(within_tol(Y_test1, Y_right, eps))
-        #print "cosine-iris", numpy.abs(Y_test1 - Y_right).max()
+        #print "cosine-iris", np.abs(Y_test1 - Y_right).max()
 
     def test_pdist_cosine_iris_nonC(self):
         "Tests pdist(X, 'test_cosine') [the non-C implementation] on the Iris data set."
@@ -291,17 +290,17 @@
         X = eo['pdist-double-inp']
         Y_right = eo['pdist-cityblock']
         Y_test1 = pdist(X, 'cityblock')
-        #print "cityblock", numpy.abs(Y_test1 - Y_right).max()
+        #print "cityblock", np.abs(Y_test1 - Y_right).max()
         self.failUnless(within_tol(Y_test1, Y_right, eps))
 
     def test_pdist_cityblock_random_float32(self):
         "Tests pdist(X, 'cityblock') on random data. (float32)"
         eps = 1e-06
         # Get the data: the input matrix and the right output.
-        X = numpy.float32(eo['pdist-double-inp'])
+        X = np.float32(eo['pdist-double-inp'])
         Y_right = eo['pdist-cityblock']
         Y_test1 = pdist(X, 'cityblock')
-        #print "cityblock", numpy.abs(Y_test1 - Y_right).max()
+        #print "cityblock", np.abs(Y_test1 - Y_right).max()
         self.failUnless(within_tol(Y_test1, Y_right, eps))
 
     def test_pdist_cityblock_random_nonC(self):
@@ -322,17 +321,17 @@
 
         Y_test1 = pdist(X, 'cityblock')
         self.failUnless(within_tol(Y_test1, Y_right, eps))
-        #print "cityblock-iris", numpy.abs(Y_test1 - Y_right).max()
+        #print "cityblock-iris", np.abs(Y_test1 - Y_right).max()
 
     def test_pdist_cityblock_iris_float32(self):
         "Tests pdist(X, 'cityblock') on the Iris data set. (float32)"
         eps = 1e-06
         # Get the data: the input matrix and the right output.
-        X = numpy.float32(eo['iris'])
+        X = np.float32(eo['iris'])
         Y_right = eo['pdist-cityblock-iris']
 
         Y_test1 = pdist(X, 'cityblock')
-        print "cityblock-iris-float32", numpy.abs(Y_test1 - Y_right).max()
+        print "cityblock-iris-float32", np.abs(Y_test1 - Y_right).max()
         self.failUnless(within_tol(Y_test1, Y_right, eps))
 
     def test_pdist_cityblock_iris_nonC(self):
@@ -353,18 +352,18 @@
         Y_right = eo['pdist-correlation']
 
         Y_test1 = pdist(X, 'correlation')
-        #print "correlation", numpy.abs(Y_test1 - Y_right).max()
+        #print "correlation", np.abs(Y_test1 - Y_right).max()
         self.failUnless(within_tol(Y_test1, Y_right, eps))
 
     def test_pdist_correlation_random_float32(self):
         "Tests pdist(X, 'correlation') on random data. (float32)"
         eps = 1e-07
         # Get the data: the input matrix and the right output.
-        X = numpy.float32(eo['pdist-double-inp'])
+        X = np.float32(eo['pdist-double-inp'])
         Y_right = eo['pdist-correlation']
 
         Y_test1 = pdist(X, 'correlation')
-        #print "correlation", numpy.abs(Y_test1 - Y_right).max()
+        #print "correlation", np.abs(Y_test1 - Y_right).max()
         self.failUnless(within_tol(Y_test1, Y_right, eps))
 
     def test_pdist_correlation_random_nonC(self):
@@ -384,7 +383,7 @@
         Y_right = eo['pdist-correlation-iris']
 
         Y_test1 = pdist(X, 'correlation')
-        #print "correlation-iris", numpy.abs(Y_test1 - Y_right).max()
+        #print "correlation-iris", np.abs(Y_test1 - Y_right).max()
         self.failUnless(within_tol(Y_test1, Y_right, eps))
 
     def test_pdist_correlation_iris_float32(self):
@@ -392,10 +391,10 @@
         eps = 1e-07
         # Get the data: the input matrix and the right output.
         X = eo['iris']
-        Y_right = numpy.float32(eo['pdist-correlation-iris'])
+        Y_right = np.float32(eo['pdist-correlation-iris'])
 
         Y_test1 = pdist(X, 'correlation')
-        print "correlation-iris", numpy.abs(Y_test1 - Y_right).max()
+        print "correlation-iris", np.abs(Y_test1 - Y_right).max()
         self.failUnless(within_tol(Y_test1, Y_right, eps))
 
     def test_pdist_correlation_iris_nonC(self):
@@ -405,7 +404,7 @@
         X = eo['iris']
         Y_right = eo['pdist-correlation-iris']
         Y_test2 = pdist(X, 'test_correlation')
-        #print "test-correlation-iris", numpy.abs(Y_test2 - Y_right).max()
+        #print "test-correlation-iris", np.abs(Y_test2 - Y_right).max()
         self.failUnless(within_tol(Y_test2, Y_right, eps))
 
     ################# minkowski
@@ -418,18 +417,18 @@
         Y_right = eo['pdist-minkowski-3.2']
 
         Y_test1 = pdist(X, 'minkowski', 3.2)
-        #print "minkowski", numpy.abs(Y_test1 - Y_right).max()
+        #print "minkowski", np.abs(Y_test1 - Y_right).max()
         self.failUnless(within_tol(Y_test1, Y_right, eps))
 
     def test_pdist_minkowski_random_float32(self):
         "Tests pdist(X, 'minkowski') on random data. (float32)"
         eps = 1e-05
         # Get the data: the input matrix and the right output.
-        X = numpy.float32(eo['pdist-double-inp'])
+        X = np.float32(eo['pdist-double-inp'])
         Y_right = eo['pdist-minkowski-3.2']
 
         Y_test1 = pdist(X, 'minkowski', 3.2)
-        #print "minkowski", numpy.abs(Y_test1 - Y_right).max()
+        #print "minkowski", np.abs(Y_test1 - Y_right).max()
         self.failUnless(within_tol(Y_test1, Y_right, eps))
 
     def test_pdist_minkowski_random_nonC(self):
@@ -448,17 +447,17 @@
         X = eo['iris']
         Y_right = eo['pdist-minkowski-3.2-iris']
         Y_test1 = pdist(X, 'minkowski', 3.2)
-        #print "minkowski-iris-3.2", numpy.abs(Y_test1 - Y_right).max()
+        #print "minkowski-iris-3.2", np.abs(Y_test1 - Y_right).max()
         self.failUnless(within_tol(Y_test1, Y_right, eps))
 
     def test_pdist_minkowski_iris_float32(self):
         "Tests pdist(X, 'minkowski') on iris data. (float32)"
         eps = 1e-07
         # Get the data: the input matrix and the right output.
-        X = numpy.float32(eo['iris'])
+        X = np.float32(eo['iris'])
         Y_right = eo['pdist-minkowski-3.2-iris']
         Y_test1 = pdist(X, 'minkowski', 3.2)
-        #print "minkowski-iris-3.2", numpy.abs(Y_test1 - Y_right).max()
+        #print "minkowski-iris-3.2", np.abs(Y_test1 - Y_right).max()
         self.failUnless(within_tol(Y_test1, Y_right, eps))
 
     def test_pdist_minkowski_iris_nonC(self):
@@ -477,18 +476,18 @@
         X = eo['iris']
         Y_right = eo['pdist-minkowski-5.8-iris']
         Y_test1 = pdist(X, 'minkowski', 5.8)
-        #print "minkowski-iris-5.8", numpy.abs(Y_test1 - Y_right).max()
+        #print "minkowski-iris-5.8", np.abs(Y_test1 - Y_right).max()
         self.failUnless(within_tol(Y_test1, Y_right, eps))
 
     def test_pdist_minkowski_iris_float32(self):
         "Tests pdist(X, 'minkowski') on iris data. (float32)"
         eps = 1e-06
         # Get the data: the input matrix and the right output.
-        X = numpy.float32(eo['iris'])
+        X = np.float32(eo['iris'])
         Y_right = eo['pdist-minkowski-5.8-iris']
 
         Y_test1 = pdist(X, 'minkowski', 5.8)
-        print "minkowski-iris-5.8", numpy.abs(Y_test1 - Y_right).max()
+        print "minkowski-iris-5.8", np.abs(Y_test1 - Y_right).max()
         self.failUnless(within_tol(Y_test1, Y_right, eps))
 
     def test_pdist_minkowski_iris_nonC(self):
@@ -509,18 +508,18 @@
         Y_right = eo['pdist-hamming']
 
         Y_test1 = pdist(X, 'hamming')
-        #print "hamming", numpy.abs(Y_test1 - Y_right).max()
+        #print "hamming", np.abs(Y_test1 - Y_right).max()
         self.failUnless(within_tol(Y_test1, Y_right, eps))
 
     def test_pdist_hamming_random_float32(self):
         "Tests pdist(X, 'hamming') on random data."
         eps = 1e-07
         # Get the data: the input matrix and the right output.
-        X = numpy.float32(eo['pdist-boolean-inp'])
+        X = np.float32(eo['pdist-boolean-inp'])
         Y_right = eo['pdist-hamming']
 
         Y_test1 = pdist(X, 'hamming')
-        #print "hamming", numpy.abs(Y_test1 - Y_right).max()
+        #print "hamming", np.abs(Y_test1 - Y_right).max()
         self.failUnless(within_tol(Y_test1, Y_right, eps))
 
     def test_pdist_hamming_random_nonC(self):
@@ -530,7 +529,7 @@
         X = eo['pdist-boolean-inp']
         Y_right = eo['pdist-hamming']
         Y_test2 = pdist(X, 'test_hamming')
-        #print "test-hamming", numpy.abs(Y_test2 - Y_right).max()
+        #print "test-hamming", np.abs(Y_test2 - Y_right).max()
         self.failUnless(within_tol(Y_test2, Y_right, eps))
 
     ################### pdist: hamming (double)
@@ -538,30 +537,30 @@
         "Tests pdist(X, 'hamming') on random data."
         eps = 1e-07
         # Get the data: the input matrix and the right output.
-        X = numpy.float64(eo['pdist-boolean-inp'])
+        X = np.float64(eo['pdist-boolean-inp'])
         Y_right = eo['pdist-hamming']
         Y_test1 = pdist(X, 'hamming')
-        #print "hamming", numpy.abs(Y_test1 - Y_right).max()
+        #print "hamming", np.abs(Y_test1 - Y_right).max()
         self.failUnless(within_tol(Y_test1, Y_right, eps))
 
     def test_pdist_dhamming_random_float32(self):
         "Tests pdist(X, 'hamming') on random data. (float32)"
         eps = 1e-07
         # Get the data: the input matrix and the right output.
-        X = numpy.float32(eo['pdist-boolean-inp'])
+        X = np.float32(eo['pdist-boolean-inp'])
         Y_right = eo['pdist-hamming']
         Y_test1 = pdist(X, 'hamming')
-        #print "hamming", numpy.abs(Y_test1 - Y_right).max()
+        #print "hamming", np.abs(Y_test1 - Y_right).max()
         self.failUnless(within_tol(Y_test1, Y_right, eps))
 
     def test_pdist_dhamming_random_nonC(self):
         "Tests pdist(X, 'test_hamming') [the non-C implementation] on random data."
         eps = 1e-07
         # Get the data: the input matrix and the right output.
-        X = numpy.float64(eo['pdist-boolean-inp'])
+        X = np.float64(eo['pdist-boolean-inp'])
         Y_right = eo['pdist-hamming']
         Y_test2 = pdist(X, 'test_hamming')
-        #print "test-hamming", numpy.abs(Y_test2 - Y_right).max()
+        #print "test-hamming", np.abs(Y_test2 - Y_right).max()
         self.failUnless(within_tol(Y_test2, Y_right, eps))
 
     ################### pdist: jaccard
@@ -573,18 +572,18 @@
         Y_right = eo['pdist-jaccard']
 
         Y_test1 = pdist(X, 'jaccard')
-        #print "jaccard", numpy.abs(Y_test1 - Y_right).max()
+        #print "jaccard", np.abs(Y_test1 - Y_right).max()
         self.failUnless(within_tol(Y_test1, Y_right, eps))
 
     def test_pdist_jaccard_random_float32(self):
         "Tests pdist(X, 'jaccard') on random data. (float32)"
         eps = 1e-08
         # Get the data: the input matrix and the right output.
-        X = numpy.float32(eo['pdist-boolean-inp'])
+        X = np.float32(eo['pdist-boolean-inp'])
         Y_right = eo['pdist-jaccard']
 
         Y_test1 = pdist(X, 'jaccard')
-        #print "jaccard", numpy.abs(Y_test1 - Y_right).max()
+        #print "jaccard", np.abs(Y_test1 - Y_right).max()
         self.failUnless(within_tol(Y_test1, Y_right, eps))
 
     def test_pdist_jaccard_random_nonC(self):
@@ -594,7 +593,7 @@
         X = eo['pdist-boolean-inp']
         Y_right = eo['pdist-jaccard']
         Y_test2 = pdist(X, 'test_jaccard')
-        #print "test-jaccard", numpy.abs(Y_test2 - Y_right).max()
+        #print "test-jaccard", np.abs(Y_test2 - Y_right).max()
         self.failUnless(within_tol(Y_test2, Y_right, eps))
 
     ################### pdist: jaccard (double)
@@ -602,32 +601,32 @@
         "Tests pdist(X, 'jaccard') on random data."
         eps = 1e-08
         # Get the data: the input matrix and the right output.
-        X = numpy.float64(eo['pdist-boolean-inp'])
+        X = np.float64(eo['pdist-boolean-inp'])
         Y_right = eo['pdist-jaccard']
 
         Y_test1 = pdist(X, 'jaccard')
-        #print "jaccard", numpy.abs(Y_test1 - Y_right).max()
+        #print "jaccard", np.abs(Y_test1 - Y_right).max()
         self.failUnless(within_tol(Y_test1, Y_right, eps))
 
     def test_pdist_djaccard_random_float32(self):
         "Tests pdist(X, 'jaccard') on random data. (float32)"
         eps = 1e-08
         # Get the data: the input matrix and the right output.
-        X = numpy.float32(eo['pdist-boolean-inp'])
+        X = np.float32(eo['pdist-boolean-inp'])
         Y_right = eo['pdist-jaccard']
 
         Y_test1 = pdist(X, 'jaccard')
-        #print "jaccard", numpy.abs(Y_test1 - Y_right).max()
+        #print "jaccard", np.abs(Y_test1 - Y_right).max()
         self.failUnless(within_tol(Y_test1, Y_right, eps))
 
     def test_pdist_djaccard_random_nonC(self):
         "Tests pdist(X, 'test_jaccard') [the non-C implementation] on random data."
         eps = 1e-08
         # Get the data: the input matrix and the right output.
-        X = numpy.float64(eo['pdist-boolean-inp'])
+        X = np.float64(eo['pdist-boolean-inp'])
         Y_right = eo['pdist-jaccard']
         Y_test2 = pdist(X, 'test_jaccard')
-        #print "test-jaccard", numpy.abs(Y_test2 - Y_right).max()
+        #print "test-jaccard", np.abs(Y_test2 - Y_right).max()
         self.failUnless(within_tol(Y_test2, Y_right, eps))
 
     ################### pdist: chebychev
@@ -639,18 +638,18 @@
         Y_right = eo['pdist-chebychev']
 
         Y_test1 = pdist(X, 'chebychev')
-        #print "chebychev", numpy.abs(Y_test1 - Y_right).max()
+        #print "chebychev", np.abs(Y_test1 - Y_right).max()
         self.failUnless(within_tol(Y_test1, Y_right, eps))
 
     def test_pdist_chebychev_random_float32(self):
         "Tests pdist(X, 'chebychev') on random data. (float32)"
         eps = 1e-07
         # Get the data: the input matrix and the right output.
-        X = numpy.float32(eo['pdist-double-inp'])
+        X = np.float32(eo['pdist-double-inp'])
         Y_right = eo['pdist-chebychev']
 
         Y_test1 = pdist(X, 'chebychev')
-        print "chebychev", numpy.abs(Y_test1 - Y_right).max()
+        print "chebychev", np.abs(Y_test1 - Y_right).max()
         self.failUnless(within_tol(Y_test1, Y_right, eps))
 
     def test_pdist_chebychev_random_nonC(self):
@@ -660,7 +659,7 @@
         X = eo['pdist-double-inp']
         Y_right = eo['pdist-chebychev']
         Y_test2 = pdist(X, 'test_chebychev')
-        #print "test-chebychev", numpy.abs(Y_test2 - Y_right).max()
+        #print "test-chebychev", np.abs(Y_test2 - Y_right).max()
         self.failUnless(within_tol(Y_test2, Y_right, eps))
 
     def test_pdist_chebychev_iris(self):
@@ -670,17 +669,17 @@
         X = eo['iris']
         Y_right = eo['pdist-chebychev-iris']
         Y_test1 = pdist(X, 'chebychev')
-        #print "chebychev-iris", numpy.abs(Y_test1 - Y_right).max()
+        #print "chebychev-iris", np.abs(Y_test1 - Y_right).max()
         self.failUnless(within_tol(Y_test1, Y_right, eps))
 
     def test_pdist_chebychev_iris_float32(self):
         "Tests pdist(X, 'chebychev') on the Iris data set. (float32)"
         eps = 1e-06
         # Get the data: the input matrix and the right output.
-        X = numpy.float32(eo['iris'])
+        X = np.float32(eo['iris'])
         Y_right = eo['pdist-chebychev-iris']
         Y_test1 = pdist(X, 'chebychev')
-        print "chebychev-iris", numpy.abs(Y_test1 - Y_right).max()
+        print "chebychev-iris", np.abs(Y_test1 - Y_right).max()
         self.failUnless(within_tol(Y_test1, Y_right, eps))
 
     def test_pdist_chebychev_iris_nonC(self):
@@ -690,58 +689,58 @@
         X = eo['iris']
         Y_right = eo['pdist-chebychev-iris']
         Y_test2 = pdist(X, 'test_chebychev')
-        #print "test-chebychev-iris", numpy.abs(Y_test2 - Y_right).max()
+        #print "test-chebychev-iris", np.abs(Y_test2 - Y_right).max()
         self.failUnless(within_tol(Y_test2, Y_right, eps))
 
     def test_pdist_matching_mtica1(self):
         "Tests matching(*,*) with mtica example #1 (nums)."
-        m = matching(numpy.array([1, 0, 1, 1, 0]),
-                     numpy.array([1, 1, 0, 1, 1]))
-        m2 = matching(numpy.array([1, 0, 1, 1, 0], dtype=numpy.bool),
-                      numpy.array([1, 1, 0, 1, 1], dtype=numpy.bool))
-        self.failUnless(numpy.abs(m - 0.6) <= 1e-10)
-        self.failUnless(numpy.abs(m2 - 0.6) <= 1e-10)
+        m = matching(np.array([1, 0, 1, 1, 0]),
+                     np.array([1, 1, 0, 1, 1]))
+        m2 = matching(np.array([1, 0, 1, 1, 0], dtype=np.bool),
+                      np.array([1, 1, 0, 1, 1], dtype=np.bool))
+        self.failUnless(np.abs(m - 0.6) <= 1e-10)
+        self.failUnless(np.abs(m2 - 0.6) <= 1e-10)
 
     def test_pdist_matching_mtica2(self):
         "Tests matching(*,*) with mtica example #2."
-        m = matching(numpy.array([1, 0, 1]),
-                     numpy.array([1, 1, 0]))
-        m2 = matching(numpy.array([1, 0, 1], dtype=numpy.bool),
-                      numpy.array([1, 1, 0], dtype=numpy.bool))
-        self.failUnless(numpy.abs(m - (2.0/3.0)) <= 1e-10)
-        self.failUnless(numpy.abs(m2 - (2.0/3.0)) <= 1e-10)
+        m = matching(np.array([1, 0, 1]),
+                     np.array([1, 1, 0]))
+        m2 = matching(np.array([1, 0, 1], dtype=np.bool),
+                      np.array([1, 1, 0], dtype=np.bool))
+        self.failUnless(np.abs(m - (2.0/3.0)) <= 1e-10)
+        self.failUnless(np.abs(m2 - (2.0/3.0)) <= 1e-10)
 
     def test_pdist_matching_match(self):
         "Tests pdist(X, 'matching') to see if the two implementations match on random boolean input data."
         D = eo['random-bool-data']
-        B = numpy.bool_(D)
+        B = np.bool_(D)
         print B.shape, B.dtype
         eps = 1e-10
         y1 = pdist(B, "matching")
         y2 = pdist(B, "test_matching")
         y3 = pdist(D, "test_matching")
-        print numpy.abs(y1-y2).max()
-        print numpy.abs(y1-y3).max()
+        print np.abs(y1-y2).max()
+        print np.abs(y1-y3).max()
         self.failUnless(within_tol(y1, y2, eps))
         self.failUnless(within_tol(y2, y3, eps))
 
     def test_pdist_jaccard_mtica1(self):
         "Tests jaccard(*,*) with mtica example #1."
-        m = jaccard(numpy.array([1, 0, 1, 1, 0]),
-                    numpy.array([1, 1, 0, 1, 1]))
-        m2 = jaccard(numpy.array([1, 0, 1, 1, 0], dtype=numpy.bool),
-                     numpy.array([1, 1, 0, 1, 1], dtype=numpy.bool))
-        self.failUnless(numpy.abs(m - 0.6) <= 1e-10)
-        self.failUnless(numpy.abs(m2 - 0.6) <= 1e-10)
+        m = jaccard(np.array([1, 0, 1, 1, 0]),
+                    np.array([1, 1, 0, 1, 1]))
+        m2 = jaccard(np.array([1, 0, 1, 1, 0], dtype=np.bool),
+                     np.array([1, 1, 0, 1, 1], dtype=np.bool))
+        self.failUnless(np.abs(m - 0.6) <= 1e-10)
+        self.failUnless(np.abs(m2 - 0.6) <= 1e-10)
 
     def test_pdist_jaccard_mtica2(self):
         "Tests jaccard(*,*) with mtica example #2."
-        m = jaccard(numpy.array([1, 0, 1]),
-                    numpy.array([1, 1, 0]))
-        m2 = jaccard(numpy.array([1, 0, 1], dtype=numpy.bool),
-                     numpy.array([1, 1, 0], dtype=numpy.bool))
-        self.failUnless(numpy.abs(m - (2.0/3.0)) <= 1e-10)
-        self.failUnless(numpy.abs(m2 - (2.0/3.0)) <= 1e-10)
+        m = jaccard(np.array([1, 0, 1]),
+                    np.array([1, 1, 0]))
+        m2 = jaccard(np.array([1, 0, 1], dtype=np.bool),
+                     np.array([1, 1, 0], dtype=np.bool))
+        self.failUnless(np.abs(m - (2.0/3.0)) <= 1e-10)
+        self.failUnless(np.abs(m2 - (2.0/3.0)) <= 1e-10)
 
     def test_pdist_jaccard_match(self):
         "Tests pdist(X, 'jaccard') to see if the two implementations match on random double input data."
@@ -750,31 +749,31 @@
         eps = 1e-10
         y1 = pdist(D, "jaccard")
         y2 = pdist(D, "test_jaccard")
-        y3 = pdist(numpy.bool_(D), "test_jaccard")
-        print numpy.abs(y1-y2).max()
-        print numpy.abs(y2-y3).max()
+        y3 = pdist(np.bool_(D), "test_jaccard")
+        print np.abs(y1-y2).max()
+        print np.abs(y2-y3).max()
         self.failUnless(within_tol(y1, y2, eps))
         self.failUnless(within_tol(y2, y3, eps))
 
     def test_pdist_yule_mtica1(self):
         "Tests yule(*,*) with mtica example #1."
-        m = yule(numpy.array([1, 0, 1, 1, 0]),
-                 numpy.array([1, 1, 0, 1, 1]))
-        m2 = yule(numpy.array([1, 0, 1, 1, 0], dtype=numpy.bool),
-                  numpy.array([1, 1, 0, 1, 1], dtype=numpy.bool))
+        m = yule(np.array([1, 0, 1, 1, 0]),
+                 np.array([1, 1, 0, 1, 1]))
+        m2 = yule(np.array([1, 0, 1, 1, 0], dtype=np.bool),
+                  np.array([1, 1, 0, 1, 1], dtype=np.bool))
         print m
-        self.failUnless(numpy.abs(m - 2.0) <= 1e-10)
-        self.failUnless(numpy.abs(m2 - 2.0) <= 1e-10)
+        self.failUnless(np.abs(m - 2.0) <= 1e-10)
+        self.failUnless(np.abs(m2 - 2.0) <= 1e-10)
 
     def test_pdist_yule_mtica2(self):
         "Tests yule(*,*) with mtica example #2."
-        m = yule(numpy.array([1, 0, 1]),
-                 numpy.array([1, 1, 0]))
-        m2 = yule(numpy.array([1, 0, 1], dtype=numpy.bool),
-                  numpy.array([1, 1, 0], dtype=numpy.bool))
+        m = yule(np.array([1, 0, 1]),
+                 np.array([1, 1, 0]))
+        m2 = yule(np.array([1, 0, 1], dtype=np.bool),
+                  np.array([1, 1, 0], dtype=np.bool))
         print m
-        self.failUnless(numpy.abs(m - 2.0) <= 1e-10)
-        self.failUnless(numpy.abs(m2 - 2.0) <= 1e-10)
+        self.failUnless(np.abs(m - 2.0) <= 1e-10)
+        self.failUnless(np.abs(m2 - 2.0) <= 1e-10)
 
     def test_pdist_yule_match(self):
         "Tests pdist(X, 'yule') to see if the two implementations match on random double input data."
@@ -783,31 +782,31 @@
         eps = 1e-10
         y1 = pdist(D, "yule")
         y2 = pdist(D, "test_yule")
-        y3 = pdist(numpy.bool_(D), "test_yule")
-        print numpy.abs(y1-y2).max()
-        print numpy.abs(y2-y3).max()
+        y3 = pdist(np.bool_(D), "test_yule")
+        print np.abs(y1-y2).max()
+        print np.abs(y2-y3).max()
         self.failUnless(within_tol(y1, y2, eps))
         self.failUnless(within_tol(y2, y3, eps))
 
     def test_pdist_dice_mtica1(self):
         "Tests dice(*,*) with mtica example #1."
-        m = dice(numpy.array([1, 0, 1, 1, 0]),
-                 numpy.array([1, 1, 0, 1, 1]))
-        m2 = dice(numpy.array([1, 0, 1, 1, 0], dtype=numpy.bool),
-                  numpy.array([1, 1, 0, 1, 1], dtype=numpy.bool))
+        m = dice(np.array([1, 0, 1, 1, 0]),
+                 np.array([1, 1, 0, 1, 1]))
+        m2 = dice(np.array([1, 0, 1, 1, 0], dtype=np.bool),
+                  np.array([1, 1, 0, 1, 1], dtype=np.bool))
         print m
-        self.failUnless(numpy.abs(m - (3.0/7.0)) <= 1e-10)
-        self.failUnless(numpy.abs(m2 - (3.0/7.0)) <= 1e-10)
+        self.failUnless(np.abs(m - (3.0/7.0)) <= 1e-10)
+        self.failUnless(np.abs(m2 - (3.0/7.0)) <= 1e-10)
 
     def test_pdist_dice_mtica2(self):
         "Tests dice(*,*) with mtica example #2."
-        m = dice(numpy.array([1, 0, 1]),
-                 numpy.array([1, 1, 0]))
-        m2 = dice(numpy.array([1, 0, 1], dtype=numpy.bool),
-                  numpy.array([1, 1, 0], dtype=numpy.bool))
+        m = dice(np.array([1, 0, 1]),
+                 np.array([1, 1, 0]))
+        m2 = dice(np.array([1, 0, 1], dtype=np.bool),
+                  np.array([1, 1, 0], dtype=np.bool))
         print m
-        self.failUnless(numpy.abs(m - 0.5) <= 1e-10)
-        self.failUnless(numpy.abs(m2 - 0.5) <= 1e-10)
+        self.failUnless(np.abs(m - 0.5) <= 1e-10)
+        self.failUnless(np.abs(m2 - 0.5) <= 1e-10)
 
     def test_pdist_dice_match(self):
         "Tests pdist(X, 'dice') to see if the two implementations match on random double input data."
@@ -817,30 +816,30 @@
         y1 = pdist(D, "dice")
         y2 = pdist(D, "test_dice")
         y3 = pdist(D, "test_dice")
-        print numpy.abs(y1-y2).max()
-        print numpy.abs(y2-y3).max()
+        print np.abs(y1-y2).max()
+        print np.abs(y2-y3).max()
         self.failUnless(within_tol(y1, y2, eps))
         self.failUnless(within_tol(y2, y3, eps))
 
     def test_pdist_sokalsneath_mtica1(self):
         "Tests sokalsneath(*,*) with mtica example #1."
-        m = sokalsneath(numpy.array([1, 0, 1, 1, 0]),
-                        numpy.array([1, 1, 0, 1, 1]))
-        m2 = sokalsneath(numpy.array([1, 0, 1, 1, 0], dtype=numpy.bool),
-                         numpy.array([1, 1, 0, 1, 1], dtype=numpy.bool))
+        m = sokalsneath(np.array([1, 0, 1, 1, 0]),
+                        np.array([1, 1, 0, 1, 1]))
+        m2 = sokalsneath(np.array([1, 0, 1, 1, 0], dtype=np.bool),
+                         np.array([1, 1, 0, 1, 1], dtype=np.bool))
         print m
-        self.failUnless(numpy.abs(m - (3.0/4.0)) <= 1e-10)
-        self.failUnless(numpy.abs(m2 - (3.0/4.0)) <= 1e-10)
+        self.failUnless(np.abs(m - (3.0/4.0)) <= 1e-10)
+        self.failUnless(np.abs(m2 - (3.0/4.0)) <= 1e-10)
 
     def test_pdist_sokalsneath_mtica2(self):
         "Tests sokalsneath(*,*) with mtica example #2."
-        m = sokalsneath(numpy.array([1, 0, 1]),
-                        numpy.array([1, 1, 0]))
-        m2 = sokalsneath(numpy.array([1, 0, 1], dtype=numpy.bool),
-                         numpy.array([1, 1, 0], dtype=numpy.bool))
+        m = sokalsneath(np.array([1, 0, 1]),
+                        np.array([1, 1, 0]))
+        m2 = sokalsneath(np.array([1, 0, 1], dtype=np.bool),
+                         np.array([1, 1, 0], dtype=np.bool))
         print m
-        self.failUnless(numpy.abs(m - (4.0/5.0)) <= 1e-10)
-        self.failUnless(numpy.abs(m2 - (4.0/5.0)) <= 1e-10)
+        self.failUnless(np.abs(m - (4.0/5.0)) <= 1e-10)
+        self.failUnless(np.abs(m2 - (4.0/5.0)) <= 1e-10)
 
     def test_pdist_sokalsneath_match(self):
         "Tests pdist(X, 'sokalsneath') to see if the two implementations match on random double input data."
@@ -849,31 +848,31 @@
         eps = 1e-10
         y1 = pdist(D, "sokalsneath")
         y2 = pdist(D, "test_sokalsneath")
-        y3 = pdist(numpy.bool_(D), "test_sokalsneath")
-        print numpy.abs(y1-y2).max()
-        print numpy.abs(y2-y3).max()
+        y3 = pdist(np.bool_(D), "test_sokalsneath")
+        print np.abs(y1-y2).max()
+        print np.abs(y2-y3).max()
         self.failUnless(within_tol(y1, y2, eps))
         self.failUnless(within_tol(y2, y3, eps))
 
     def test_pdist_rogerstanimoto_mtica1(self):
         "Tests rogerstanimoto(*,*) with mtica example #1."
-        m = rogerstanimoto(numpy.array([1, 0, 1, 1, 0]),
-                           numpy.array([1, 1, 0, 1, 1]))
-        m2 = rogerstanimoto(numpy.array([1, 0, 1, 1, 0], dtype=numpy.bool),
-                            numpy.array([1, 1, 0, 1, 1], dtype=numpy.bool))
+        m = rogerstanimoto(np.array([1, 0, 1, 1, 0]),
+                           np.array([1, 1, 0, 1, 1]))
+        m2 = rogerstanimoto(np.array([1, 0, 1, 1, 0], dtype=np.bool),
+                            np.array([1, 1, 0, 1, 1], dtype=np.bool))
         print m
-        self.failUnless(numpy.abs(m - (3.0/4.0)) <= 1e-10)
-        self.failUnless(numpy.abs(m2 - (3.0/4.0)) <= 1e-10)
+        self.failUnless(np.abs(m - (3.0/4.0)) <= 1e-10)
+        self.failUnless(np.abs(m2 - (3.0/4.0)) <= 1e-10)
 
     def test_pdist_rogerstanimoto_mtica2(self):
         "Tests rogerstanimoto(*,*) with mtica example #2."
-        m = rogerstanimoto(numpy.array([1, 0, 1]),
-                           numpy.array([1, 1, 0]))
-        m2 = rogerstanimoto(numpy.array([1, 0, 1], dtype=numpy.bool),
-                            numpy.array([1, 1, 0], dtype=numpy.bool))
+        m = rogerstanimoto(np.array([1, 0, 1]),
+                           np.array([1, 1, 0]))
+        m2 = rogerstanimoto(np.array([1, 0, 1], dtype=np.bool),
+                            np.array([1, 1, 0], dtype=np.bool))
         print m
-        self.failUnless(numpy.abs(m - (4.0/5.0)) <= 1e-10)
-        self.failUnless(numpy.abs(m2 - (4.0/5.0)) <= 1e-10)
+        self.failUnless(np.abs(m - (4.0/5.0)) <= 1e-10)
+        self.failUnless(np.abs(m2 - (4.0/5.0)) <= 1e-10)
 
     def test_pdist_rogerstanimoto_match(self):
         "Tests pdist(X, 'rogerstanimoto') to see if the two implementations match on random double input data."
@@ -882,31 +881,31 @@
         eps = 1e-10
         y1 = pdist(D, "rogerstanimoto")
         y2 = pdist(D, "test_rogerstanimoto")
-        y3 = pdist(numpy.bool_(D), "test_rogerstanimoto")
-        print numpy.abs(y1-y2).max()
-        print numpy.abs(y2-y3).max()
+        y3 = pdist(np.bool_(D), "test_rogerstanimoto")
+        print np.abs(y1-y2).max()
+        print np.abs(y2-y3).max()
         self.failUnless(within_tol(y1, y2, eps))
         self.failUnless(within_tol(y2, y3, eps))
 
     def test_pdist_russellrao_mtica1(self):
         "Tests russellrao(*,*) with mtica example #1."
-        m = russellrao(numpy.array([1, 0, 1, 1, 0]),
-                       numpy.array([1, 1, 0, 1, 1]))
-        m2 = russellrao(numpy.array([1, 0, 1, 1, 0], dtype=numpy.bool),
-                        numpy.array([1, 1, 0, 1, 1], dtype=numpy.bool))
+        m = russellrao(np.array([1, 0, 1, 1, 0]),
+                       np.array([1, 1, 0, 1, 1]))
+        m2 = russellrao(np.array([1, 0, 1, 1, 0], dtype=np.bool),
+                        np.array([1, 1, 0, 1, 1], dtype=np.bool))
         print m
-        self.failUnless(numpy.abs(m - (3.0/5.0)) <= 1e-10)
-        self.failUnless(numpy.abs(m2 - (3.0/5.0)) <= 1e-10)
+        self.failUnless(np.abs(m - (3.0/5.0)) <= 1e-10)
+        self.failUnless(np.abs(m2 - (3.0/5.0)) <= 1e-10)
 
     def test_pdist_russellrao_mtica2(self):
         "Tests russellrao(*,*) with mtica example #2."
-        m = russellrao(numpy.array([1, 0, 1]),
-                       numpy.array([1, 1, 0]))
-        m2 = russellrao(numpy.array([1, 0, 1], dtype=numpy.bool),
-                        numpy.array([1, 1, 0], dtype=numpy.bool))
+        m = russellrao(np.array([1, 0, 1]),
+                       np.array([1, 1, 0]))
+        m2 = russellrao(np.array([1, 0, 1], dtype=np.bool),
+                        np.array([1, 1, 0], dtype=np.bool))
         print m
-        self.failUnless(numpy.abs(m - (2.0/3.0)) <= 1e-10)
-        self.failUnless(numpy.abs(m2 - (2.0/3.0)) <= 1e-10)
+        self.failUnless(np.abs(m - (2.0/3.0)) <= 1e-10)
+        self.failUnless(np.abs(m2 - (2.0/3.0)) <= 1e-10)
 
     def test_pdist_russellrao_match(self):
         "Tests pdist(X, 'russellrao') to see if the two implementations match on random double input data."
@@ -915,9 +914,9 @@
         eps = 1e-10
         y1 = pdist(D, "russellrao")
         y2 = pdist(D, "test_russellrao")
-        y3 = pdist(numpy.bool_(D), "test_russellrao")
-        print numpy.abs(y1-y2).max()
-        print numpy.abs(y2-y3).max()
+        y3 = pdist(np.bool_(D), "test_russellrao")
+        print np.abs(y1-y2).max()
+        print np.abs(y2-y3).max()
         self.failUnless(within_tol(y1, y2, eps))
         self.failUnless(within_tol(y2, y3, eps))
 
@@ -928,9 +927,9 @@
         eps = 1e-10
         y1 = pdist(D, "sokalmichener")
         y2 = pdist(D, "test_sokalmichener")
-        y3 = pdist(numpy.bool_(D), "test_sokalmichener")
-        print numpy.abs(y1-y2).max()
-        print numpy.abs(y2-y3).max()
+        y3 = pdist(np.bool_(D), "test_sokalmichener")
+        print np.abs(y1-y2).max()
+        print np.abs(y2-y3).max()
         self.failUnless(within_tol(y1, y2, eps))
         self.failUnless(within_tol(y2, y3, eps))
 
@@ -941,9 +940,9 @@
         eps = 1e-10
         y1 = pdist(D, "kulsinski")
         y2 = pdist(D, "test_kulsinski")
-        y3 = pdist(numpy.bool_(D), "test_kulsinski")
-        print numpy.abs(y1-y2).max()
+        y3 = pdist(np.bool_(D), "test_kulsinski")
+        print np.abs(y1-y2).max()
         self.failUnless(within_tol(y1, y2, eps))
 
 def within_tol(a, b, tol):
-    return numpy.abs(a - b).max() < tol
+    return np.abs(a - b).max() < tol

Modified: trunk/scipy/cluster/tests/test_hierarchy.py
===================================================================
--- trunk/scipy/cluster/tests/test_hierarchy.py	2008-08-08 01:30:30 UTC (rev 4615)
+++ trunk/scipy/cluster/tests/test_hierarchy.py	2008-08-08 05:33:08 UTC (rev 4616)
@@ -35,13 +35,14 @@
 
 import sys
 import os.path
-import numpy
 
+import numpy as np
 from numpy.testing import *
+
 from scipy.cluster.hierarchy import squareform, linkage, from_mlab_linkage, numobs_dm, numobs_y, numobs_linkage, inconsistent
 from scipy.cluster.distance import pdist, matching, jaccard, dice, sokalsneath, rogerstanimoto, russellrao, yule
 
-_tdist = numpy.array([[0,    662,  877,  255,  412,  996],
+_tdist = np.array([[0,    662,  877,  255,  412,  996],
                       [662,  0,    295,  468,  268,  400],
                       [877,  295,  0,    754,  564,  138],
                       [255,  468,  754,  0,    219,  869],
@@ -79,9 +80,9 @@
     for fn in _filenames:
         name = fn.replace(".txt", "").replace("-ml", "")
         fqfn = os.path.join(os.path.dirname(__file__), fn)
-        eo[name] = numpy.loadtxt(open(fqfn))
+        eo[name] = np.loadtxt(open(fqfn))
         #print "%s: %s   %s" % (name, str(eo[name].shape), str(eo[name].dtype))
-    #eo['pdist-boolean-inp'] = numpy.bool_(eo['pdist-boolean-inp'])
+    #eo['pdist-boolean-inp'] = np.bool_(eo['pdist-boolean-inp'])
 
 load_testing_files()
 
@@ -90,36 +91,36 @@
     ################### squareform
     def test_squareform_empty_matrix(self):
         "Tests squareform on an empty matrix."
-        A = numpy.zeros((0,0))
-        rA = squareform(numpy.array(A, dtype='double'))
+        A = np.zeros((0,0))
+        rA = squareform(np.array(A, dtype='double'))
         self.failUnless(rA.shape == (0,))
 
     def test_squareform_empty_vector(self):
-        v = numpy.zeros((0,))
-        rv = squareform(numpy.array(v, dtype='double'))
+        v = np.zeros((0,))
+        rv = squareform(np.array(v, dtype='double'))
         self.failUnless(rv.shape == (1,1))
         self.failUnless(rv[0, 0] == 0)
 
     def test_squareform_1by1_matrix(self):
         "Tests squareform on a 1x1 matrix."
-        A = numpy.zeros((1,1))
-        rA = squareform(numpy.array(A, dtype='double'))
+        A = np.zeros((1,1))
+        rA = squareform(np.array(A, dtype='double'))
         self.failUnless(rA.shape == (0,))
 
     def test_squareform_one_vector(self):
         "Tests squareform on a 1-D array, length=1."
-        v = numpy.ones((1,)) * 8.3
-        rv = squareform(numpy.array(v, dtype='double'))
+        v = np.ones((1,)) * 8.3
+        rv = squareform(np.array(v, dtype='double'))
         self.failUnless(rv.shape == (2,2))
         self.failUnless(rv[0,1] == 8.3)
         self.failUnless(rv[1,0] == 8.3)
 
     def test_squareform_2by2_matrix(self):
         "Tests squareform on a 2x2 matrix."
-        A = numpy.zeros((2,2))
+        A = np.zeros((2,2))
         A[0,1]=0.8
         A[1,0]=0.8
-        rA = squareform(numpy.array(A, dtype='double'))
+        rA = squareform(np.array(A, dtype='double'))
         self.failUnless(rA.shape == (1,))
         self.failUnless(rA[0] == 0.8)
 
@@ -129,7 +130,7 @@
             yield self.check_squareform_multi_matrix(n)
 
     def check_squareform_multi_matrix(self, n):
-        X = numpy.random.rand(n, 4)
+        X = np.random.rand(n, 4)
         Y = pdist(X)
         self.failUnless(len(Y.shape) == 1)
         A = squareform(Y)
@@ -156,7 +157,7 @@
     def test_numobs_dm_multi_matrix(self):
         "Tests numobs_dm with observation matrices of multiple sizes."
         for n in xrange(1, 10):
-            X = numpy.random.rand(n, 4)
+            X = np.random.rand(n, 4)
             Y = pdist(X)
             A = squareform(Y)
             if verbose >= 3:
@@ -166,7 +167,7 @@
     def test_numobs_y_multi_matrix(self):
         "Tests numobs_y with observation matrices of multiple sizes."
         for n in xrange(2, 10):
-            X = numpy.random.rand(n, 4)
+            X = np.random.rand(n, 4)
             Y = pdist(X)
             #print A.shape, Y.shape, Yr.shape
             self.failUnless(numobs_y(Y) == n)
@@ -174,7 +175,7 @@
     def test_numobs_linkage_multi_matrix(self):
         "Tests numobs_linkage with observation matrices of multiple sizes."
         for n in xrange(2, 10):
-            X = numpy.random.rand(n, 4)
+            X = np.random.rand(n, 4)
             Y = pdist(X)
             Z = linkage(Y)
             #print Z
@@ -206,7 +207,7 @@
         Zmlab = eo['linkage-average-tdist']
         eps = 1e-05
         expectedZ = from_mlab_linkage(Zmlab)
-        #print Z, expectedZ, numpy.abs(Z - expectedZ).max()
+        #print Z, expectedZ, np.abs(Z - expectedZ).max()
         self.failUnless(within_tol(Z, expectedZ, eps))
 
     def test_linkage_weighted_tdist(self):
@@ -215,7 +216,7 @@
         Zmlab = eo['linkage-weighted-tdist']
         eps = 1e-10
         expectedZ = from_mlab_linkage(Zmlab)
-        #print Z, expectedZ, numpy.abs(Z - expectedZ).max()
+        #print Z, expectedZ, np.abs(Z - expectedZ).max()
         self.failUnless(within_tol(Z, expectedZ, eps))
 
 class TestInconsistent(TestCase):
@@ -230,12 +231,11 @@
     R = inconsistent(Z, i)
     Rright = eo['inconsistent-single-tdist-depth-' + str(i)]
     eps = 1e-05
-    print numpy.abs(R - Rright).max()
+    print np.abs(R - Rright).max()
     self.failUnless(within_tol(R, Rright, eps))
 
 def within_tol(a, b, tol):
-    return numpy.abs(a - b).max() < tol
+    return np.abs(a - b).max() < tol
 
 if __name__ == "__main__":
     run_module_suite()
-

Modified: trunk/scipy/cluster/tests/test_vq.py
===================================================================
--- trunk/scipy/cluster/tests/test_vq.py	2008-08-08 01:30:30 UTC (rev 4615)
+++ trunk/scipy/cluster/tests/test_vq.py	2008-08-08 05:33:08 UTC (rev 4616)
@@ -3,15 +3,12 @@
 # David Cournapeau
 # Last Change: Tue Jun 24 04:00 PM 2008 J
 
-# For now, just copy the tests from sandbox.pyem, so we can check that
-# kmeans works OK for trivial examples.
-
 import sys
 import os.path
+
+import numpy as np
 from numpy.testing import *
 
-import numpy as N
-
 from scipy.cluster.vq import kmeans, kmeans2, py_vq, py_vq2, _py_vq_1d, vq, ClusterError
 try:
     from scipy.cluster import _vq
@@ -25,35 +22,35 @@
 DATAFILE1 = os.path.join(os.path.dirname(__file__), "data.txt")
 
 # Global data
-X   = N.array([[3.0, 3], [4, 3], [4, 2],
+X   = np.array([[3.0, 3], [4, 3], [4, 2],
                [9, 2], [5, 1], [6, 2], [9, 4],
                [5, 2], [5, 4], [7, 4], [6, 5]])
 
-CODET1  = N.array([[3.0000, 3.0000],
+CODET1  = np.array([[3.0000, 3.0000],
                    [6.2000, 4.0000],
                    [5.8000, 1.8000]])
 
-CODET2  = N.array([[11.0/3, 8.0/3],
+CODET2  = np.array([[11.0/3, 8.0/3],
                    [6.7500, 4.2500],
                    [6.2500, 1.7500]])
 
-LABEL1  = N.array([0, 1, 2, 2, 2, 2, 1, 2, 1, 1, 1])
+LABEL1  = np.array([0, 1, 2, 2, 2, 2, 1, 2, 1, 1, 1])
 
 class TestVq(TestCase):
     def test_py_vq(self):
-        initc = N.concatenate(([[X[0]], [X[1]], [X[2]]]))
+        initc = np.concatenate(([[X[0]], [X[1]], [X[2]]]))
         code = initc.copy()
         label1 = py_vq(X, initc)[0]
         assert_array_equal(label1, LABEL1)
 
     def test_py_vq2(self):
-        initc = N.concatenate(([[X[0]], [X[1]], [X[2]]]))
+        initc = np.concatenate(([[X[0]], [X[1]], [X[2]]]))
         code = initc.copy()
         label1 = py_vq2(X, initc)[0]
         assert_array_equal(label1, LABEL1)
 
     def test_vq(self):
-        initc = N.concatenate(([[X[0]], [X[1]], [X[2]]]))
+        initc = np.concatenate(([[X[0]], [X[1]], [X[2]]]))
         code = initc.copy()
         if TESTC:
             label1, dist = _vq.vq(X, initc)
@@ -68,7 +65,7 @@
     #    initc = data[:3]
     #    code = initc.copy()
     #    a, b = _py_vq_1d(data, initc)
-    #    ta, tb = py_vq(data[:, N.newaxis], initc[:, N.newaxis])
+    #    ta, tb = py_vq(data[:, np.newaxis], initc[:, np.newaxis])
     #    assert_array_equal(a, ta)
     #    assert_array_equal(b, tb)
 
@@ -79,7 +76,7 @@
         code = initc.copy()
         if TESTC:
             a, b = _vq.vq(data, initc)
-            ta, tb = py_vq(data[:, N.newaxis], initc[:, N.newaxis])
+            ta, tb = py_vq(data[:, np.newaxis], initc[:, np.newaxis])
             assert_array_equal(a, ta)
             assert_array_equal(b, tb)
         else:
@@ -87,7 +84,7 @@
 
 class TestKMean(TestCase):
     def test_kmeans_simple(self):
-        initc = N.concatenate(([[X[0]], [X[1]], [X[2]]]))
+        initc = np.concatenate(([[X[0]], [X[1]], [X[2]]]))
         code = initc.copy()
         code1 = kmeans(X, code, iter = 1)[0]
 
@@ -95,9 +92,9 @@
 
     def test_kmeans_lost_cluster(self):
         """This will cause kmean to have a cluster with no points."""
-        data = N.fromfile(open(DATAFILE1), sep = ", ")
+        data = np.fromfile(open(DATAFILE1), sep = ", ")
         data = data.reshape((200, 2))
-        initk = N.array([[-1.8127404, -0.67128041],
+        initk = np.array([[-1.8127404, -0.67128041],
                          [ 2.04621601, 0.07401111],
                          [-2.31149087,-0.05160469]])
 
@@ -111,7 +108,7 @@
 
     def test_kmeans2_simple(self):
         """Testing simple call to kmeans2 and its results."""
-        initc = N.concatenate(([[X[0]], [X[1]], [X[2]]]))
+        initc = np.concatenate(([[X[0]], [X[1]], [X[2]]]))
         code = initc.copy()
         code1 = kmeans2(X, code, iter = 1)[0]
         code2 = kmeans2(X, code, iter = 2)[0]
@@ -121,7 +118,7 @@
 
     def test_kmeans2_rank1(self):
         """Testing simple call to kmeans2 with rank 1 data."""
-        data = N.fromfile(open(DATAFILE1), sep = ", ")
+        data = np.fromfile(open(DATAFILE1), sep = ", ")
         data = data.reshape((200, 2))
         data1 = data[:, 0]
         data2 = data[:, 1]
@@ -133,7 +130,7 @@
 
     def test_kmeans2_rank1_2(self):
         """Testing simple call to kmeans2 with rank 1 data."""
-        data = N.fromfile(open(DATAFILE1), sep = ", ")
+        data = np.fromfile(open(DATAFILE1), sep = ", ")
         data = data.reshape((200, 2))
         data1 = data[:, 0]
 
@@ -141,7 +138,7 @@
 
     def test_kmeans2_init(self):
         """Testing that kmeans2 init methods work."""
-        data = N.fromfile(open(DATAFILE1), sep = ", ")
+        data = np.fromfile(open(DATAFILE1), sep = ", ")
         data = data.reshape((200, 2))
 
         kmeans2(data, 3, minit = 'random')
@@ -176,7 +173,7 @@
             pass
 
         try:
-            kmeans2(X, N.array([]))
+            kmeans2(X, np.array([]))
             raise AssertionError("kmeans2 with 0 clusters should fail.")
         except ValueError:
             pass




More information about the Scipy-svn mailing list