我们从Python开源项目中,提取了以下26个代码示例,用于说明如何使用numpy.alen()。
def setdiff(eq1, eq2): eq1, eq2 = eqsize(eq1, eq2) c1 = [None] * eq1.shape c2 = [None] * eq2.shape for i in range(0, eq1.size): c1.append[i] = hash(eq2[i]) for i in range(0, eq2.size): c2[i] = hash(eq2[i]) ia = np.delete(np.arange(np.alen(c1)), np.searchsorted(c1, c2)) ia = (ia[:]).conj().T p = eq1[ia] return p, ia
def _validate_dataset(ds): if not type(ds.data) is np.ndarray: return ['Dataset.data must be a numpy.ndarray'] elif np.alen(ds.data) < 1: return ['Dataset.data must not be empty'] elif not np.issubdtype(ds.data.dtype, np.float64): return ['Dataset.data.dtype must be numpy.float64'] if ds.is_scale: if len(ds.data.shape) != 1: return ['Scales must be one-dimensional'] if np.any(np.diff(ds.data) <= 0): return ['Scales must be strictly monotonic increasing'] else: if (len(ds.data.shape) >= 1) and (ds.data.shape[0] > 0) and not (len(ds.data.shape) == len(ds.scales)): return ['The number of scales does not match the number of dimensions'] return []
def test_basic(self): m = np.array([1, 2, 3]) self.assertEqual(np.alen(m), 3) m = np.array([[1, 2, 3], [4, 5, 7]]) self.assertEqual(np.alen(m), 2) m = [1, 2, 3] self.assertEqual(np.alen(m), 3) m = [[1, 2, 3], [4, 5, 7]] self.assertEqual(np.alen(m), 2)
def test_singleton(self): self.assertEqual(np.alen(5), 1)
def alen(a): """ Return the length of the first dimension of the input array. Parameters ---------- a : array_like Input array. Returns ------- alen : int Length of the first dimension of `a`. See Also -------- shape, size Examples -------- >>> a = np.zeros((7,4,5)) >>> a.shape[0] 7 >>> np.alen(a) 7 """ try: return len(a) except TypeError: return len(array(a, ndmin=1))
def shape(a): """ Return the shape of an array. Parameters ---------- a : array_like Input array. Returns ------- shape : tuple of ints The elements of the shape tuple give the lengths of the corresponding array dimensions. See Also -------- alen ndarray.shape : Equivalent array method. Examples -------- >>> np.shape(np.eye(3)) (3, 3) >>> np.shape([[1, 2]]) (1, 2) >>> np.shape([0]) (1,) >>> np.shape(0) () >>> a = np.array([(1, 2), (3, 4)], dtype=[('x', 'i4'), ('y', 'i4')]) >>> np.shape(a) (2,) >>> a.shape (2,) """ try: result = a.shape except AttributeError: result = asarray(a).shape return result