Python numpy.setxor1d() Examples
The following are 30 code examples for showing how to use numpy.setxor1d(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
You may check out the related API usage on the sidebar.
You may also want to check out all available functions/classes of the module
numpy
, or try the search function
.
Example 1
Project: recruit Author: Frank-qlu File: arraysetops.py License: Apache License 2.0 | 5 votes |
def setxor1d(ar1, ar2, assume_unique=False): """ Find the set exclusive-or of two arrays. Return the sorted, unique values that are in only one (not both) of the input arrays. Parameters ---------- ar1, ar2 : array_like Input arrays. assume_unique : bool If True, the input arrays are both assumed to be unique, which can speed up the calculation. Default is False. Returns ------- setxor1d : ndarray Sorted 1D array of unique values that are in only one of the input arrays. Examples -------- >>> a = np.array([1, 2, 3, 2, 4]) >>> b = np.array([2, 3, 5, 7, 5]) >>> np.setxor1d(a,b) array([1, 4, 5, 7]) """ if not assume_unique: ar1 = unique(ar1) ar2 = unique(ar2) aux = np.concatenate((ar1, ar2)) if aux.size == 0: return aux aux.sort() flag = np.concatenate(([True], aux[1:] != aux[:-1], [True])) return aux[flag[1:] & flag[:-1]]
Example 2
Project: lambda-packs Author: ryfeus File: arraysetops.py License: MIT License | 5 votes |
def setxor1d(ar1, ar2, assume_unique=False): """ Find the set exclusive-or of two arrays. Return the sorted, unique values that are in only one (not both) of the input arrays. Parameters ---------- ar1, ar2 : array_like Input arrays. assume_unique : bool If True, the input arrays are both assumed to be unique, which can speed up the calculation. Default is False. Returns ------- setxor1d : ndarray Sorted 1D array of unique values that are in only one of the input arrays. Examples -------- >>> a = np.array([1, 2, 3, 2, 4]) >>> b = np.array([2, 3, 5, 7, 5]) >>> np.setxor1d(a,b) array([1, 4, 5, 7]) """ if not assume_unique: ar1 = unique(ar1) ar2 = unique(ar2) aux = np.concatenate((ar1, ar2)) if aux.size == 0: return aux aux.sort() flag = np.concatenate(([True], aux[1:] != aux[:-1], [True])) return aux[flag[1:] & flag[:-1]]
Example 3
Project: vnpy_crypto Author: birforce File: arraysetops.py License: MIT License | 5 votes |
def setxor1d(ar1, ar2, assume_unique=False): """ Find the set exclusive-or of two arrays. Return the sorted, unique values that are in only one (not both) of the input arrays. Parameters ---------- ar1, ar2 : array_like Input arrays. assume_unique : bool If True, the input arrays are both assumed to be unique, which can speed up the calculation. Default is False. Returns ------- setxor1d : ndarray Sorted 1D array of unique values that are in only one of the input arrays. Examples -------- >>> a = np.array([1, 2, 3, 2, 4]) >>> b = np.array([2, 3, 5, 7, 5]) >>> np.setxor1d(a,b) array([1, 4, 5, 7]) """ if not assume_unique: ar1 = unique(ar1) ar2 = unique(ar2) aux = np.concatenate((ar1, ar2)) if aux.size == 0: return aux aux.sort() flag = np.concatenate(([True], aux[1:] != aux[:-1], [True])) return aux[flag[1:] & flag[:-1]]
Example 4
Project: Mastering-Elasticsearch-7.0 Author: PacktPublishing File: arraysetops.py License: MIT License | 5 votes |
def setxor1d(ar1, ar2, assume_unique=False): """ Find the set exclusive-or of two arrays. Return the sorted, unique values that are in only one (not both) of the input arrays. Parameters ---------- ar1, ar2 : array_like Input arrays. assume_unique : bool If True, the input arrays are both assumed to be unique, which can speed up the calculation. Default is False. Returns ------- setxor1d : ndarray Sorted 1D array of unique values that are in only one of the input arrays. Examples -------- >>> a = np.array([1, 2, 3, 2, 4]) >>> b = np.array([2, 3, 5, 7, 5]) >>> np.setxor1d(a,b) array([1, 4, 5, 7]) """ if not assume_unique: ar1 = unique(ar1) ar2 = unique(ar2) aux = np.concatenate((ar1, ar2)) if aux.size == 0: return aux aux.sort() flag = np.concatenate(([True], aux[1:] != aux[:-1], [True])) return aux[flag[1:] & flag[:-1]]
Example 5
Project: GraphicDesignPatternByPython Author: Relph1119 File: arraysetops.py License: MIT License | 5 votes |
def setxor1d(ar1, ar2, assume_unique=False): """ Find the set exclusive-or of two arrays. Return the sorted, unique values that are in only one (not both) of the input arrays. Parameters ---------- ar1, ar2 : array_like Input arrays. assume_unique : bool If True, the input arrays are both assumed to be unique, which can speed up the calculation. Default is False. Returns ------- setxor1d : ndarray Sorted 1D array of unique values that are in only one of the input arrays. Examples -------- >>> a = np.array([1, 2, 3, 2, 4]) >>> b = np.array([2, 3, 5, 7, 5]) >>> np.setxor1d(a,b) array([1, 4, 5, 7]) """ if not assume_unique: ar1 = unique(ar1) ar2 = unique(ar2) aux = np.concatenate((ar1, ar2)) if aux.size == 0: return aux aux.sort() flag = np.concatenate(([True], aux[1:] != aux[:-1], [True])) return aux[flag[1:] & flag[:-1]]
Example 6
Project: predictive-maintenance-using-machine-learning Author: awslabs File: arraysetops.py License: Apache License 2.0 | 5 votes |
def setxor1d(ar1, ar2, assume_unique=False): """ Find the set exclusive-or of two arrays. Return the sorted, unique values that are in only one (not both) of the input arrays. Parameters ---------- ar1, ar2 : array_like Input arrays. assume_unique : bool If True, the input arrays are both assumed to be unique, which can speed up the calculation. Default is False. Returns ------- setxor1d : ndarray Sorted 1D array of unique values that are in only one of the input arrays. Examples -------- >>> a = np.array([1, 2, 3, 2, 4]) >>> b = np.array([2, 3, 5, 7, 5]) >>> np.setxor1d(a,b) array([1, 4, 5, 7]) """ if not assume_unique: ar1 = unique(ar1) ar2 = unique(ar2) aux = np.concatenate((ar1, ar2)) if aux.size == 0: return aux aux.sort() flag = np.concatenate(([True], aux[1:] != aux[:-1], [True])) return aux[flag[1:] & flag[:-1]]
Example 7
Project: pySINDy Author: luckystarufo File: arraysetops.py License: MIT License | 5 votes |
def setxor1d(ar1, ar2, assume_unique=False): """ Find the set exclusive-or of two arrays. Return the sorted, unique values that are in only one (not both) of the input arrays. Parameters ---------- ar1, ar2 : array_like Input arrays. assume_unique : bool If True, the input arrays are both assumed to be unique, which can speed up the calculation. Default is False. Returns ------- setxor1d : ndarray Sorted 1D array of unique values that are in only one of the input arrays. Examples -------- >>> a = np.array([1, 2, 3, 2, 4]) >>> b = np.array([2, 3, 5, 7, 5]) >>> np.setxor1d(a,b) array([1, 4, 5, 7]) """ if not assume_unique: ar1 = unique(ar1) ar2 = unique(ar2) aux = np.concatenate((ar1, ar2)) if aux.size == 0: return aux aux.sort() flag = np.concatenate(([True], aux[1:] != aux[:-1], [True])) return aux[flag[1:] & flag[:-1]]
Example 8
Project: sisl Author: zerothi File: base.py License: GNU Lesser General Public License v3.0 | 5 votes |
def within_index(self, *args, **kwargs): A = self.A.within_index(*args, **kwargs) B = self.B.within_index(*args, **kwargs) return setxor1d(A, B, assume_unique=True)
Example 9
Project: e3fp Author: keiserlab File: fprint.py License: GNU Lesser General Public License v3.0 | 5 votes |
def __xor__(self, other): if not isinstance(other, Fingerprint): raise E3FPInvalidFingerprintError( "variable is %s not Fingerprint" % (other.__class__.__name__) ) if self.bits != other.bits: raise E3FPBitsValueError( "cannot compare fingerprints of different sizes" ) return Fingerprint( np.setxor1d(self.indices, other.indices, assume_unique=True), bits=self.bits, )
Example 10
Project: coffeegrindsize Author: jgagneastro File: arraysetops.py License: MIT License | 5 votes |
def setxor1d(ar1, ar2, assume_unique=False): """ Find the set exclusive-or of two arrays. Return the sorted, unique values that are in only one (not both) of the input arrays. Parameters ---------- ar1, ar2 : array_like Input arrays. assume_unique : bool If True, the input arrays are both assumed to be unique, which can speed up the calculation. Default is False. Returns ------- setxor1d : ndarray Sorted 1D array of unique values that are in only one of the input arrays. Examples -------- >>> a = np.array([1, 2, 3, 2, 4]) >>> b = np.array([2, 3, 5, 7, 5]) >>> np.setxor1d(a,b) array([1, 4, 5, 7]) """ if not assume_unique: ar1 = unique(ar1) ar2 = unique(ar2) aux = np.concatenate((ar1, ar2)) if aux.size == 0: return aux aux.sort() flag = np.concatenate(([True], aux[1:] != aux[:-1], [True])) return aux[flag[1:] & flag[:-1]]
Example 11
Project: landlab Author: landlab File: hand_calculator.py License: MIT License | 5 votes |
def run_one_step(self): is_drainage_node = self._channel_mask is_drainage_node[self._grid.open_boundary_nodes] = 1 # check for pits self_draining_nodes = np.where( self._receivers == np.arange(self._grid.number_of_nodes) ) pits = np.setxor1d(self_draining_nodes, self._grid.boundary_nodes) if pits.any(): warn( "Pits detected in the flow directions supplied. " "Pits will be treated as drainage nodes." ) is_drainage_node[pits] = 1 # iterate downstream through stack to find nearest drainage elevation nearest_drainage_elev = np.empty(self._elev.shape) for n in self._node_order: r = self._receivers[n] # if not drainage node set drainage elevation to downstream. if not is_drainage_node[n]: nearest_drainage_elev[n] = nearest_drainage_elev[r] else: # set elevation of drainage to self. nearest_drainage_elev[n] = self._elev[n] self._hand[:] = self._elev - nearest_drainage_elev
Example 12
Project: am3 Author: ElementAI File: AM3_TADAM.py License: Apache License 2.0 | 5 votes |
def get_train_datasets(flags): mini_imagenet = _load_mini_imagenet(data_dir=flags.data_dir, split='sources') few_shot_data_train = Dataset(mini_imagenet) pretrain_data_train, pretrain_data_test = None, None if flags.feat_extract_pretrain: train_idx = np.random.choice(range(len(mini_imagenet[0])), size=int(0.9 * len(mini_imagenet[0])), replace=False) test_idx = np.setxor1d(range(len(mini_imagenet[0])), train_idx) new_labels = mini_imagenet[1] for i, old_class in enumerate(set(mini_imagenet[1])): new_labels[mini_imagenet[1] == old_class] = i pretrain_data_train = Dataset((mini_imagenet[0][train_idx], new_labels[train_idx])) pretrain_data_test = Dataset((mini_imagenet[0][test_idx], new_labels[test_idx])) return few_shot_data_train, pretrain_data_train, pretrain_data_test
Example 13
Project: am3 Author: ElementAI File: AM3_TADAM.py License: Apache License 2.0 | 5 votes |
def get_few_shot_idxs(labels, classes, num_shots): train_idxs, test_idxs = [], [] idxs = np.arange(len(labels)) for cl in classes: class_idxs = idxs[labels == cl] class_idxs_train = np.random.choice(class_idxs, size=num_shots, replace=False) class_idxs_test = np.setxor1d(class_idxs, class_idxs_train) train_idxs.extend(class_idxs_train) test_idxs.extend(class_idxs_test) assert set(class_idxs_train).isdisjoint(test_idxs) return np.array(train_idxs), np.array(test_idxs)
Example 14
Project: am3 Author: ElementAI File: protonet++.py License: Apache License 2.0 | 5 votes |
def get_few_shot_idxs(labels, classes, num_shots): train_idxs, test_idxs = [], [] idxs = np.arange(len(labels)) for cl in classes: class_idxs = idxs[labels == cl] class_idxs_train = np.random.choice(class_idxs, size=num_shots, replace=False) class_idxs_test = np.setxor1d(class_idxs, class_idxs_train) train_idxs.extend(class_idxs_train) test_idxs.extend(class_idxs_test) assert set(class_idxs_train).isdisjoint(test_idxs) return np.array(train_idxs), np.array(test_idxs)
Example 15
Project: am3 Author: ElementAI File: util.py License: Apache License 2.0 | 5 votes |
def get_few_shot_idxs(self, labels, classes, num_shots): train_idxs, test_idxs = [], [] idxs = np.arange(len(labels)) for cl in classes: class_idxs = idxs[labels == cl] class_idxs_train = np.random.choice(class_idxs, size=num_shots, replace=False) class_idxs_test = np.setxor1d(class_idxs, class_idxs_train) train_idxs.extend(class_idxs_train) test_idxs.extend(class_idxs_test) assert set(class_idxs_train).isdisjoint(test_idxs) return np.array(train_idxs), np.array(test_idxs)
Example 16
Project: am3 Author: ElementAI File: AM3_protonet++.py License: Apache License 2.0 | 5 votes |
def get_few_shot_idxs(labels, classes, num_shots): train_idxs, test_idxs = [], [] idxs = np.arange(len(labels)) for cl in classes: class_idxs = idxs[labels == cl] class_idxs_train = np.random.choice(class_idxs, size=num_shots, replace=False) class_idxs_test = np.setxor1d(class_idxs, class_idxs_train) train_idxs.extend(class_idxs_train) test_idxs.extend(class_idxs_test) assert set(class_idxs_train).isdisjoint(test_idxs) return np.array(train_idxs), np.array(test_idxs)
Example 17
Project: am3 Author: ElementAI File: tadam.py License: Apache License 2.0 | 5 votes |
def get_few_shot_idxs(labels, classes, num_shots): train_idxs, test_idxs = [], [] idxs = np.arange(len(labels)) for cl in classes: class_idxs = idxs[labels == cl] class_idxs_train = np.random.choice(class_idxs, size=num_shots, replace=False) class_idxs_test = np.setxor1d(class_idxs, class_idxs_train) train_idxs.extend(class_idxs_train) test_idxs.extend(class_idxs_test) assert set(class_idxs_train).isdisjoint(test_idxs) return np.array(train_idxs), np.array(test_idxs)
Example 18
Project: Carnets Author: holzschu File: test_quantity_non_ufuncs.py License: BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_setxor1d(self): self.check2(np.setxor1d)
Example 19
Project: Carnets Author: holzschu File: arraysetops.py License: BSD 3-Clause "New" or "Revised" License | 5 votes |
def setxor1d(ar1, ar2, assume_unique=False): """ Find the set exclusive-or of two arrays. Return the sorted, unique values that are in only one (not both) of the input arrays. Parameters ---------- ar1, ar2 : array_like Input arrays. assume_unique : bool If True, the input arrays are both assumed to be unique, which can speed up the calculation. Default is False. Returns ------- setxor1d : ndarray Sorted 1D array of unique values that are in only one of the input arrays. Examples -------- >>> a = np.array([1, 2, 3, 2, 4]) >>> b = np.array([2, 3, 5, 7, 5]) >>> np.setxor1d(a,b) array([1, 4, 5, 7]) """ if not assume_unique: ar1 = unique(ar1) ar2 = unique(ar2) aux = np.concatenate((ar1, ar2)) if aux.size == 0: return aux aux.sort() flag = np.concatenate(([True], aux[1:] != aux[:-1], [True])) return aux[flag[1:] & flag[:-1]]
Example 20
Project: Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda Author: PacktPublishing File: arraysetops.py License: MIT License | 5 votes |
def setxor1d(ar1, ar2, assume_unique=False): """ Find the set exclusive-or of two arrays. Return the sorted, unique values that are in only one (not both) of the input arrays. Parameters ---------- ar1, ar2 : array_like Input arrays. assume_unique : bool If True, the input arrays are both assumed to be unique, which can speed up the calculation. Default is False. Returns ------- setxor1d : ndarray Sorted 1D array of unique values that are in only one of the input arrays. Examples -------- >>> a = np.array([1, 2, 3, 2, 4]) >>> b = np.array([2, 3, 5, 7, 5]) >>> np.setxor1d(a,b) array([1, 4, 5, 7]) """ if not assume_unique: ar1 = unique(ar1) ar2 = unique(ar2) aux = np.concatenate((ar1, ar2)) if aux.size == 0: return aux aux.sort() flag = np.concatenate(([True], aux[1:] != aux[:-1], [True])) return aux[flag[1:] & flag[:-1]]
Example 21
Project: twitter-stock-recommendation Author: alvarobartt File: arraysetops.py License: MIT License | 5 votes |
def setxor1d(ar1, ar2, assume_unique=False): """ Find the set exclusive-or of two arrays. Return the sorted, unique values that are in only one (not both) of the input arrays. Parameters ---------- ar1, ar2 : array_like Input arrays. assume_unique : bool If True, the input arrays are both assumed to be unique, which can speed up the calculation. Default is False. Returns ------- setxor1d : ndarray Sorted 1D array of unique values that are in only one of the input arrays. Examples -------- >>> a = np.array([1, 2, 3, 2, 4]) >>> b = np.array([2, 3, 5, 7, 5]) >>> np.setxor1d(a,b) array([1, 4, 5, 7]) """ if not assume_unique: ar1 = unique(ar1) ar2 = unique(ar2) aux = np.concatenate((ar1, ar2)) if aux.size == 0: return aux aux.sort() flag = np.concatenate(([True], aux[1:] != aux[:-1], [True])) return aux[flag[1:] & flag[:-1]]
Example 22
Project: lambda-packs Author: ryfeus File: arraysetops.py License: MIT License | 4 votes |
def setxor1d(ar1, ar2, assume_unique=False): """ Find the set exclusive-or of two arrays. Return the sorted, unique values that are in only one (not both) of the input arrays. Parameters ---------- ar1, ar2 : array_like Input arrays. assume_unique : bool If True, the input arrays are both assumed to be unique, which can speed up the calculation. Default is False. Returns ------- setxor1d : ndarray Sorted 1D array of unique values that are in only one of the input arrays. Examples -------- >>> a = np.array([1, 2, 3, 2, 4]) >>> b = np.array([2, 3, 5, 7, 5]) >>> np.setxor1d(a,b) array([1, 4, 5, 7]) """ if not assume_unique: ar1 = unique(ar1) ar2 = unique(ar2) aux = np.concatenate((ar1, ar2)) if aux.size == 0: return aux aux.sort() # flag = ediff1d( aux, to_end = 1, to_begin = 1 ) == 0 flag = np.concatenate(([True], aux[1:] != aux[:-1], [True])) # flag2 = ediff1d( flag ) == 0 flag2 = flag[1:] == flag[:-1] return aux[flag2]
Example 23
Project: auto-alt-text-lambda-api Author: abhisuri97 File: arraysetops.py License: MIT License | 4 votes |
def setxor1d(ar1, ar2, assume_unique=False): """ Find the set exclusive-or of two arrays. Return the sorted, unique values that are in only one (not both) of the input arrays. Parameters ---------- ar1, ar2 : array_like Input arrays. assume_unique : bool If True, the input arrays are both assumed to be unique, which can speed up the calculation. Default is False. Returns ------- setxor1d : ndarray Sorted 1D array of unique values that are in only one of the input arrays. Examples -------- >>> a = np.array([1, 2, 3, 2, 4]) >>> b = np.array([2, 3, 5, 7, 5]) >>> np.setxor1d(a,b) array([1, 4, 5, 7]) """ if not assume_unique: ar1 = unique(ar1) ar2 = unique(ar2) aux = np.concatenate((ar1, ar2)) if aux.size == 0: return aux aux.sort() # flag = ediff1d( aux, to_end = 1, to_begin = 1 ) == 0 flag = np.concatenate(([True], aux[1:] != aux[:-1], [True])) # flag2 = ediff1d( flag ) == 0 flag2 = flag[1:] == flag[:-1] return aux[flag2]
Example 24
Project: Computable Author: ktraunmueller File: arraysetops.py License: MIT License | 4 votes |
def setxor1d(ar1, ar2, assume_unique=False): """ Find the set exclusive-or of two arrays. Return the sorted, unique values that are in only one (not both) of the input arrays. Parameters ---------- ar1, ar2 : array_like Input arrays. assume_unique : bool If True, the input arrays are both assumed to be unique, which can speed up the calculation. Default is False. Returns ------- setxor1d : ndarray Sorted 1D array of unique values that are in only one of the input arrays. Examples -------- >>> a = np.array([1, 2, 3, 2, 4]) >>> b = np.array([2, 3, 5, 7, 5]) >>> np.setxor1d(a,b) array([1, 4, 5, 7]) """ if not assume_unique: ar1 = unique(ar1) ar2 = unique(ar2) aux = np.concatenate( (ar1, ar2) ) if aux.size == 0: return aux aux.sort() # flag = ediff1d( aux, to_end = 1, to_begin = 1 ) == 0 flag = np.concatenate( ([True], aux[1:] != aux[:-1], [True] ) ) # flag2 = ediff1d( flag ) == 0 flag2 = flag[1:] == flag[:-1] return aux[flag2]
Example 25
Project: Fluid-Designer Author: Microvellum File: arraysetops.py License: GNU General Public License v3.0 | 4 votes |
def setxor1d(ar1, ar2, assume_unique=False): """ Find the set exclusive-or of two arrays. Return the sorted, unique values that are in only one (not both) of the input arrays. Parameters ---------- ar1, ar2 : array_like Input arrays. assume_unique : bool If True, the input arrays are both assumed to be unique, which can speed up the calculation. Default is False. Returns ------- setxor1d : ndarray Sorted 1D array of unique values that are in only one of the input arrays. Examples -------- >>> a = np.array([1, 2, 3, 2, 4]) >>> b = np.array([2, 3, 5, 7, 5]) >>> np.setxor1d(a,b) array([1, 4, 5, 7]) """ if not assume_unique: ar1 = unique(ar1) ar2 = unique(ar2) aux = np.concatenate((ar1, ar2)) if aux.size == 0: return aux aux.sort() # flag = ediff1d( aux, to_end = 1, to_begin = 1 ) == 0 flag = np.concatenate(([True], aux[1:] != aux[:-1], [True])) # flag2 = ediff1d( flag ) == 0 flag2 = flag[1:] == flag[:-1] return aux[flag2]
Example 26
Project: mxnet-lambda Author: awslabs File: arraysetops.py License: Apache License 2.0 | 4 votes |
def setxor1d(ar1, ar2, assume_unique=False): """ Find the set exclusive-or of two arrays. Return the sorted, unique values that are in only one (not both) of the input arrays. Parameters ---------- ar1, ar2 : array_like Input arrays. assume_unique : bool If True, the input arrays are both assumed to be unique, which can speed up the calculation. Default is False. Returns ------- setxor1d : ndarray Sorted 1D array of unique values that are in only one of the input arrays. Examples -------- >>> a = np.array([1, 2, 3, 2, 4]) >>> b = np.array([2, 3, 5, 7, 5]) >>> np.setxor1d(a,b) array([1, 4, 5, 7]) """ if not assume_unique: ar1 = unique(ar1) ar2 = unique(ar2) aux = np.concatenate((ar1, ar2)) if aux.size == 0: return aux aux.sort() # flag = ediff1d( aux, to_end = 1, to_begin = 1 ) == 0 flag = np.concatenate(([True], aux[1:] != aux[:-1], [True])) # flag2 = ediff1d( flag ) == 0 flag2 = flag[1:] == flag[:-1] return aux[flag2]
Example 27
Project: ImageFusion Author: pfchai File: arraysetops.py License: MIT License | 4 votes |
def setxor1d(ar1, ar2, assume_unique=False): """ Find the set exclusive-or of two arrays. Return the sorted, unique values that are in only one (not both) of the input arrays. Parameters ---------- ar1, ar2 : array_like Input arrays. assume_unique : bool If True, the input arrays are both assumed to be unique, which can speed up the calculation. Default is False. Returns ------- setxor1d : ndarray Sorted 1D array of unique values that are in only one of the input arrays. Examples -------- >>> a = np.array([1, 2, 3, 2, 4]) >>> b = np.array([2, 3, 5, 7, 5]) >>> np.setxor1d(a,b) array([1, 4, 5, 7]) """ if not assume_unique: ar1 = unique(ar1) ar2 = unique(ar2) aux = np.concatenate((ar1, ar2)) if aux.size == 0: return aux aux.sort() # flag = ediff1d( aux, to_end = 1, to_begin = 1 ) == 0 flag = np.concatenate(([True], aux[1:] != aux[:-1], [True])) # flag2 = ediff1d( flag ) == 0 flag2 = flag[1:] == flag[:-1] return aux[flag2]
Example 28
Project: Splunking-Crime Author: nccgroup File: arraysetops.py License: GNU Affero General Public License v3.0 | 4 votes |
def setxor1d(ar1, ar2, assume_unique=False): """ Find the set exclusive-or of two arrays. Return the sorted, unique values that are in only one (not both) of the input arrays. Parameters ---------- ar1, ar2 : array_like Input arrays. assume_unique : bool If True, the input arrays are both assumed to be unique, which can speed up the calculation. Default is False. Returns ------- setxor1d : ndarray Sorted 1D array of unique values that are in only one of the input arrays. Examples -------- >>> a = np.array([1, 2, 3, 2, 4]) >>> b = np.array([2, 3, 5, 7, 5]) >>> np.setxor1d(a,b) array([1, 4, 5, 7]) """ if not assume_unique: ar1 = unique(ar1) ar2 = unique(ar2) aux = np.concatenate((ar1, ar2)) if aux.size == 0: return aux aux.sort() # flag = ediff1d( aux, to_end = 1, to_begin = 1 ) == 0 flag = np.concatenate(([True], aux[1:] != aux[:-1], [True])) # flag2 = ediff1d( flag ) == 0 flag2 = flag[1:] == flag[:-1] return aux[flag2]
Example 29
Project: elasticintel Author: securityclippy File: arraysetops.py License: GNU General Public License v3.0 | 4 votes |
def setxor1d(ar1, ar2, assume_unique=False): """ Find the set exclusive-or of two arrays. Return the sorted, unique values that are in only one (not both) of the input arrays. Parameters ---------- ar1, ar2 : array_like Input arrays. assume_unique : bool If True, the input arrays are both assumed to be unique, which can speed up the calculation. Default is False. Returns ------- setxor1d : ndarray Sorted 1D array of unique values that are in only one of the input arrays. Examples -------- >>> a = np.array([1, 2, 3, 2, 4]) >>> b = np.array([2, 3, 5, 7, 5]) >>> np.setxor1d(a,b) array([1, 4, 5, 7]) """ if not assume_unique: ar1 = unique(ar1) ar2 = unique(ar2) aux = np.concatenate((ar1, ar2)) if aux.size == 0: return aux aux.sort() # flag = ediff1d( aux, to_end = 1, to_begin = 1 ) == 0 flag = np.concatenate(([True], aux[1:] != aux[:-1], [True])) # flag2 = ediff1d( flag ) == 0 flag2 = flag[1:] == flag[:-1] return aux[flag2]
Example 30
Project: metaheuristics Author: thieunguyen5991 File: PFA.py License: Apache License 2.0 | 4 votes |
def _train__(self): # Init pop and calculate fitness pop = [self._create_solution__(minmax=0) for _ in range(self.pop_size)] # Find the pathfinder pop = sorted(pop, key=lambda temp: temp[self.ID_FIT]) g_best = deepcopy(pop[0]) gbest_present = deepcopy(g_best) for i in range(self.epoch): alpha, beta = np.random.uniform(1, 2, 2) A = np.random.uniform(self.domain_range[0], self.domain_range[1]) * np.exp(-2 * (i + 1) / self.epoch) ## Update the position of pathfinder and check the bound temp = gbest_present[self.ID_POS] + 2 * np.random.uniform() * (gbest_present[self.ID_POS] - g_best[self.ID_POS]) + A temp = self._amend_solution_and_return__(temp) fit = self._fitness_model__(temp) g_best = deepcopy(gbest_present) if fit < gbest_present[self.ID_FIT]: gbest_present = [temp, fit] pop[0] = deepcopy(gbest_present) ## Update positions of members, check the bound and calculate new fitness for j in range(1, self.pop_size): temp1 = deepcopy(pop[j][self.ID_POS]) t1 = beta * np.random.uniform() * (gbest_present[self.ID_POS] - temp1) my_list_idx = np.setxor1d( np.array(range(1, self.pop_size)) , np.array([j]) ) idx = np.random.choice(my_list_idx) dist = np.linalg.norm(pop[idx][self.ID_POS] - temp1) t2 = alpha * np.random.uniform() * (pop[idx][self.ID_POS] - temp1) t3 = np.random.uniform(self.domain_range[0], self.domain_range[1], self.problem_size) * (1 - (i + 1) * 1.0 / self.epoch) * dist temp1 += t1 + t2 + t3 ## Update members temp1 = self._amend_solution_and_return__(temp1) fit = self._fitness_model__(temp1) if fit < pop[j][self.ID_FIT]: pop[j] = [temp1, fit] ## Update the best solution found so far (current pathfinder) pop = sorted(pop, key=lambda temp: temp[self.ID_FIT]) current_best = deepcopy(pop[self.ID_MIN_PROBLEM]) if current_best[self.ID_FIT] < gbest_present[self.ID_FIT]: gbest_present = deepcopy(current_best) self.loss_train.append(gbest_present[self.ID_FIT]) if self.print_train: print("Generation : {0}, best result so far: {1}".format(i + 1, gbest_present[self.ID_FIT])) return gbest_present[self.ID_FIT], self.loss_train