Switch to numpy (scipy_version>1.0) changes
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from scipy import atleast_2d,asarray,ArrayType,shape,nonzero,io,transpose
|
||||
from scipy import ndarray,atleast_2d,asarray
|
||||
from scipy import sort as array_sort
|
||||
from itertools import izip
|
||||
import shelve
|
||||
@@ -40,11 +40,11 @@ class Dataset:
|
||||
self._name = name
|
||||
self._identifiers = identifiers
|
||||
self._type = 'n'
|
||||
if isinstance(array,ArrayType):
|
||||
if isinstance(array,ndarray):
|
||||
array = atleast_2d(asarray(array))
|
||||
# vectors are column vectors
|
||||
if array.shape[0]==1:
|
||||
array = transpose(array)
|
||||
array = array.T
|
||||
self.shape = array.shape
|
||||
if identifiers!=None:
|
||||
self._set_identifiers(identifiers,self._all_dims)
|
||||
@@ -55,10 +55,7 @@ class Dataset:
|
||||
self._array = array
|
||||
|
||||
else:
|
||||
raise ValueError, "Array input must be of ArrayType"
|
||||
|
||||
#def __str__(self):
|
||||
# return self._name + ":\n" + "Dim names: " + self._dims.__str__()
|
||||
raise ValueError, "Array input must be of type ndarray"
|
||||
|
||||
def __iter__(self):
|
||||
"""Returns an iterator over dimensions of dataset."""
|
||||
@@ -177,7 +174,9 @@ class Dataset:
|
||||
|
||||
|
||||
Identifiers are the unique names (strings) for a variable in a given dim.
|
||||
Index (Indices) are the Identifiers position in a matrix in a given dim."""
|
||||
Index (Indices) are the Identifiers position in a matrix in a given dim.
|
||||
If none of the input identifiers are found an empty index is returned
|
||||
"""
|
||||
if idents==None:
|
||||
index = array_sort(self._map[dim].values())
|
||||
else:
|
||||
@@ -217,7 +216,7 @@ class CategoryDataset(Dataset):
|
||||
"""
|
||||
data={}
|
||||
for name,ind in self._map[self.get_dim_name(0)].items():
|
||||
data[name] = self.get_identifiers(self.get_dim_name(1),list(nonzero(self._array[ind,:])))
|
||||
data[name] = self.get_identifiers(self.get_dim_name(1),list(self._array[ind,:].nonzero()))
|
||||
self._dictlists = data
|
||||
self.has_dictlists = True
|
||||
return data
|
||||
@@ -227,7 +226,7 @@ class CategoryDataset(Dataset):
|
||||
"""
|
||||
ret_list = []
|
||||
for cat_name,ind in self._map[self.get_dim_name(1)].items():
|
||||
ids = self.get_identifiers(self.get_dim_name(0),nonzero(self._array[:,ind]))
|
||||
ids = self.get_identifiers(self.get_dim_name(0),self._array[:,ind].nonzero())
|
||||
selection = Selection(cat_name)
|
||||
selection.select(cat_name,ids)
|
||||
ret_list.append(selection)
|
||||
@@ -263,7 +262,7 @@ class GraphDataset(Dataset):
|
||||
|
||||
"""
|
||||
import networkx as nx
|
||||
m,n = shape(A)# adjacency matrix must be of type that evals to true/false for neigbours
|
||||
m,n = A.shape# adjacency matrix must be of type that evals to true/false for neigbours
|
||||
if m!=n:
|
||||
raise IOError, "Adjacency matrix must be square"
|
||||
if nx_type=='graph':
|
||||
|
Reference in New Issue
Block a user