@@ -32,9 +32,9 @@ def slice_data(data, sub, block, subcond=None):
32
32
adjacency_matrix : numpy array
33
33
symmetric numpy array (innode, nnode)
34
34
"""
35
- if not subcond is None :
36
- return data [subcond , block , sub ]
37
- return data [block , sub ]
35
+ if subcond is None :
36
+ return data [block , sub ]
37
+ return data [subcond , block , sub ]
38
38
39
39
40
40
def format_matrix (data ,s ,b ,lk ,co ,idc = [],costlist = [],nouptri = False ):
@@ -102,7 +102,7 @@ def format_matrix2(data,s,sc,c,lk,co,idc = [],costlist=[],nouptri = False):
102
102
cmat = np .triu (cmat ,1 )
103
103
104
104
# return boolean mask
105
- return cmat
105
+ return ~ ( cmat == 0 )
106
106
107
107
def threshold_adjacency_matrix (adj_matrix , cost ):
108
108
"""docstring for threshold_adjacency_matrix(adj_matrix, cost"""
@@ -160,12 +160,18 @@ def make_cost_thresh_lookup(adjacency_matrix):
160
160
return lookup
161
161
162
162
def cost_size (nnodes ):
163
- warnings .warn ('deprecated: use make_cost_array' , DeprecationWarning )
163
+ """create a list of actual costs, tot_edges, edges_short
164
+ given a fixed number of nodes"""
165
+ warnings .warn ('this is no longer used: use make_cost_array' )
166
+
164
167
tot_edges = 0.5 * nnodes * (nnodes - 1 )
165
168
costs = np .array (range (int (tot_edges ) + 1 ), dtype = float ) / tot_edges
166
169
edges_short = tot_edges / 2
167
170
return costs , tot_edges , edges_short
168
171
172
+ def test_warning ():
173
+ """simple code to raise a warning"""
174
+ warnings .warn ('This is your warning' )
169
175
170
176
def make_cost_array (n_nodes , cost = 0.5 ):
171
177
"""Make cost array of length cost * (the number of possible edges).
@@ -642,7 +648,7 @@ def cost2thresh2(cost, sub, axis1, axis0, lk,
642
648
threshold : float
643
649
threshold value for this cost"""
644
650
645
- subject_lookup = slice_data (lk , sub , axis0 , subcond = axis1 )
651
+ subject_lookup = slice_data (lk , sub , axis1 , subcond = axis0 )
646
652
index = np .where (subject_lookup [1 ] == cost )
647
653
threshold = subject_lookup [0 ][index ]
648
654
@@ -651,14 +657,14 @@ def cost2thresh2(cost, sub, axis1, axis0, lk,
651
657
#if there are multiple thresholds, go down to the lower cost
652
658
####Is this right?!!!####
653
659
print ('Subject %s has multiple thresholds at cost %s' % (sub , cost ))
654
- print ('index 1: %s, index 2: %s' % (c , sc ))
660
+ print ('index 1: %s, index 2: %s' % (axis1 , axis0 ))
655
661
elif len (threshold ) < 1 :
656
662
idc = idc - 1
657
663
newcost = costlist [idc ]
658
664
threshold = cost2thresh2 (newcost , sub , axis1 , axis0 , lk ,
659
665
idc = idc , costlist = costlist )
660
666
print (' ' .join (['Subject %s does not have cost at %s' % (sub , cost ),
661
- 'index 1: %s, index 2: %s' % (c , sc ),
667
+ 'index 1: %s, index 2: %s' % (axis1 , axis0 ),
662
668
'nearest cost %s being used' % (newcost )]))
663
669
else :
664
670
threshold = threshold [0 ]
@@ -811,24 +817,10 @@ def fill_diagonal(a,val):
811
817
812
818
See also
813
819
--------
814
- - diag_indices: indices to access diagonals given shape information.
815
- - diag_indices_from: indices to access diagonals given an array.
820
+ - numpy. diag_indices: indices to access diagonals given shape information.
821
+ - numpy. diag_indices_from: indices to access diagonals given an array.
816
822
"""
817
- if a .ndim < 2 :
818
- raise ValueError ("array must be at least 2-d" )
819
- if a .ndim == 2 :
820
- # Explicit, fast formula for the common case. For 2-d arrays, we
821
- # accept rectangular ones.
822
- step = a .shape [1 ] + 1
823
- else :
824
- # For more than d=2, the strided formula is only valid for arrays with
825
- # all dimensions equal, so we check first.
826
- if not np .alltrue (np .diff (a .shape )== 0 ):
827
- raise ValueError ("All dimensions of input must be of equal length" )
828
- step = np .cumprod ((1 ,)+ a .shape [:- 1 ]).sum ()
829
-
830
- # Write the value out into the diagonal.
831
- a .flat [::step ] = val
823
+ return np .fill_diagonal (a ,val )
832
824
833
825
834
826
def diag_indices (n ,ndim = 2 ):
@@ -881,11 +873,10 @@ def diag_indices(n,ndim=2):
881
873
882
874
See also
883
875
--------
884
- - diag_indices_from: create the indices based on the shape of an existing
876
+ - numpy. diag_indices_from: create the indices based on the shape of an existing
885
877
array.
886
878
"""
887
- idx = np .arange (n )
888
- return (idx ,)* ndim
879
+ return np .diag_indices (n , ndim = ndim )
889
880
890
881
891
882
def diag_indices_from (arr ):
@@ -897,16 +888,9 @@ def diag_indices_from(arr):
897
888
----------
898
889
arr : array, at least 2-d
899
890
"""
900
- if not arr .ndim >= 2 :
901
- raise ValueError ("input array must be at least 2-d" )
902
- # For more than d=2, the strided formula is only valid for arrays with
903
- # all dimensions equal, so we check first.
904
- if not np .alltrue (np .diff (a .shape )== 0 ):
905
- raise ValueError ("All dimensions of input must be of equal length" )
891
+ return np .diag_indices_from (arr )
906
892
907
- return diag_indices (a .shape [0 ],a .ndim )
908
893
909
-
910
894
def mask_indices (n ,mask_func ,k = 0 ):
911
895
"""Return the indices to access (n,n) arrays, given a masking function.
912
896
0 commit comments