Python numpy.core.multiarray.array() Examples
The following are 30
code examples of numpy.core.multiarray.array().
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 also want to check out all available functions/classes of the module
numpy.core.multiarray
, or try the search function
.
Example #1
Source File: high_speed_jacobian.py From GridCal with GNU General Public License v3.0 | 6 votes |
def _create_J_without_numba(Ybus, V, pvpq, pq): # create Jacobian with standard pypower implementation. dS_dVm, dS_dVa = dSbus_dV(Ybus, V) ## evaluate Jacobian J11 = dS_dVa[array([pvpq]).T, pvpq].real J12 = dS_dVm[array([pvpq]).T, pq].real if len(pq) > 0: J21 = dS_dVa[array([pq]).T, pvpq].imag J22 = dS_dVm[array([pq]).T, pq].imag J = vstack([ hstack([J11, J12]), hstack([J21, J22]) ], format="csr") else: J = vstack([ hstack([J11, J12]) ], format="csr") return J
Example #2
Source File: functions.py From Computable with MIT License | 5 votes |
def array(sequence, typecode=None, copy=1, savespace=0, dtype=None): dtype = convtypecode2(typecode, dtype) return mu.array(sequence, dtype, copy=copy)
Example #3
Source File: test_descriptive.py From hypothetical with MIT License | 5 votes |
def test_var_standard_two_pass(self): assert_allclose(np.array(var(self.f, 'standard two pass')).reshape(4,), np.array([2, 2.25, 0.666667, 2]), rtol=1e-02) assert_allclose(np.array(var(self.h, 'standard two pass')).reshape(4,), np.array([32, 9, 3.666667, 17]), rtol=1e-02) assert_equal(var(self.fa[:, 1], 'standard two pass'), 2.25)
Example #4
Source File: test_descriptive.py From hypothetical with MIT License | 5 votes |
def test_var_youngs_cramer(self): assert_allclose(np.array(var(self.f, 'youngs cramer')).reshape(4,), np.array([2, 2.25, 0.666667, 2]), rtol=1e-02) assert_allclose(np.array(var(self.h, 'youngs cramer')).reshape(4,), np.array([32, 9, 3.666667, 17]), rtol=1e-02) assert_equal(var(self.fa[:, 1], 'youngs cramer'), 2.25)
Example #5
Source File: test_descriptive.py From hypothetical with MIT License | 5 votes |
def test_stddev(self): assert_equal(std_dev(self.fa[:, 1]), 1.5) assert_allclose(std_dev(self.fa), array([ 1.41421356, 1.5 , 0.81649658, 1.41421356]))
Example #6
Source File: test_descriptive.py From hypothetical with MIT License | 5 votes |
def test_errors(self): with pytest.raises(ValueError): var(self.f, 'NA') ff = np.array([np.array(self.f), np.array(self.f)]) with pytest.raises(ValueError): var(ff)
Example #7
Source File: test_descriptive.py From hypothetical with MIT License | 5 votes |
def test_kurtosis(self): k1 = kurtosis(self.s1) k2 = kurtosis([self.s1, self.s2], axis=1) assert_almost_equal(k1, -1.4515532544378704) assert_allclose(k2, array([-1.45155325, -1.32230624]))
Example #8
Source File: test_descriptive.py From hypothetical with MIT License | 5 votes |
def test_skewness(self): s1 = skewness(self.s1) s2 = skewness([self.s1, self.s2], axis=1) assert_almost_equal(s1, -0.028285981029545847) assert_allclose(s2, array([-0.02828598, -0.03331004]))
Example #9
Source File: functions.py From Computable with MIT License | 5 votes |
def ones(shape, typecode='l', savespace=0, dtype=None): """ones(shape, dtype=int) returns an array of the given dimensions which is initialized to all ones. """ dtype = convtypecode(typecode, dtype) a = mu.empty(shape, dtype) a.fill(1) return a
Example #10
Source File: functions.py From Computable with MIT License | 5 votes |
def zeros(shape, typecode='l', savespace=0, dtype=None): """zeros(shape, dtype=int) returns an array of the given dimensions which is initialized to all zeros """ dtype = convtypecode(typecode, dtype) return mu.zeros(shape, dtype)
Example #11
Source File: functions.py From Computable with MIT License | 5 votes |
def identity(n,typecode='l', dtype=None): """identity(n) returns the identity 2-d array of shape n x n. """ dtype = convtypecode(typecode, dtype) return nn.identity(n, dtype)
Example #12
Source File: tfvis.py From python-control with BSD 3-Clause "New" or "Revised" License | 5 votes |
def draw_pz(self, tfcn): """Draw pzmap""" self.f_pzmap.clf() # Make adaptive window size, with min [-10, 10] in range, # always atleast 25% extra space outside poles/zeros tmp = list(self.zeros)+list(self.poles)+[8] val = 1.25*max(abs(array(tmp))) plt.figure(self.f_pzmap.number) control.matlab.pzmap(tfcn) plt.suptitle('Pole-Zero Diagram') plt.axis([-val, val, -val, val])
Example #13
Source File: functions.py From Computable with MIT License | 5 votes |
def sarray(a, typecode=None, copy=False, dtype=None): dtype = convtypecode2(typecode, dtype) return mu.array(a, dtype, copy)
Example #14
Source File: functions.py From biskit with GNU General Public License v3.0 | 5 votes |
def ones(shape, typecode='l', savespace=0, dtype=None): """ones(shape, dtype=int) returns an array of the given dimensions which is initialized to all ones. """ dtype = convtypecode(typecode, dtype) a = mu.empty(shape, dtype) a.fill(1) return a
Example #15
Source File: functions.py From biskit with GNU General Public License v3.0 | 5 votes |
def zeros(shape, typecode='l', savespace=0, dtype=None): """zeros(shape, dtype=int) returns an array of the given dimensions which is initialized to all zeros """ dtype = convtypecode(typecode, dtype) return mu.zeros(shape, dtype)
Example #16
Source File: functions.py From biskit with GNU General Public License v3.0 | 5 votes |
def identity(n,typecode='l', dtype=None): """identity(n) returns the identity 2-d array of shape n x n. """ dtype = convtypecode(typecode, dtype) return nn.identity(n, dtype)
Example #17
Source File: functions.py From biskit with GNU General Public License v3.0 | 5 votes |
def array(sequence, typecode=None, copy=1, savespace=0, dtype=None): dtype = convtypecode2(typecode, dtype) return mu.array(sequence, dtype, copy=copy)
Example #18
Source File: functions.py From biskit with GNU General Public License v3.0 | 5 votes |
def sarray(a, typecode=None, copy=False, dtype=None): dtype = convtypecode2(typecode, dtype) return mu.array(a, dtype, copy)
Example #19
Source File: numeric.py From keras-lambda with MIT License | 5 votes |
def asfortranarray(a, dtype=None): """ Return an array laid out in Fortran order in memory. Parameters ---------- a : array_like Input array. dtype : str or dtype object, optional By default, the data-type is inferred from the input data. Returns ------- out : ndarray The input `a` in Fortran, or column-major, order. See Also -------- ascontiguousarray : Convert input to a contiguous (C order) array. asanyarray : Convert input to an ndarray with either row or column-major memory order. require : Return an ndarray that satisfies requirements. ndarray.flags : Information about the memory layout of the array. Examples -------- >>> x = np.arange(6).reshape(2,3) >>> y = np.asfortranarray(x) >>> x.flags['F_CONTIGUOUS'] False >>> y.flags['F_CONTIGUOUS'] True """ return array(a, dtype, copy=False, order='F', ndmin=1)
Example #20
Source File: numeric.py From keras-lambda with MIT License | 5 votes |
def ascontiguousarray(a, dtype=None): """ Return a contiguous array in memory (C order). Parameters ---------- a : array_like Input array. dtype : str or dtype object, optional Data-type of returned array. Returns ------- out : ndarray Contiguous array of same shape and content as `a`, with type `dtype` if specified. See Also -------- asfortranarray : Convert input to an ndarray with column-major memory order. require : Return an ndarray that satisfies requirements. ndarray.flags : Information about the memory layout of the array. Examples -------- >>> x = np.arange(6).reshape(2,3) >>> np.ascontiguousarray(x, dtype=np.float32) array([[ 0., 1., 2.], [ 3., 4., 5.]], dtype=float32) >>> x.flags['C_CONTIGUOUS'] True """ return array(a, dtype, copy=False, order='C', ndmin=1)
Example #21
Source File: test_descriptive.py From hypothetical with MIT License | 5 votes |
def test_var_corrected_two_pass(self): assert_allclose(np.array(var(self.f)).reshape(4,), np.array([2, 2.25, 0.666667, 2]), rtol=1e-02) assert_allclose(np.array(var(self.f, 'corrected two pass')).reshape(4,), np.array([2, 2.25, 0.666667, 2]), rtol=1e-02) assert_allclose(var(self.h).reshape(4,), np.array([32, 9, 3.666667, 17]), rtol=1e-02)
Example #22
Source File: numeric.py From keras-lambda with MIT License | 5 votes |
def identity(n, dtype=None): """ Return the identity array. The identity array is a square array with ones on the main diagonal. Parameters ---------- n : int Number of rows (and columns) in `n` x `n` output. dtype : data-type, optional Data-type of the output. Defaults to ``float``. Returns ------- out : ndarray `n` x `n` array with its main diagonal set to one, and all other elements 0. Examples -------- >>> np.identity(3) array([[ 1., 0., 0.], [ 0., 1., 0.], [ 0., 0., 1.]]) """ from numpy import eye return eye(n, dtype=dtype)
Example #23
Source File: numeric.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def ascontiguousarray(a, dtype=None): """ Return a contiguous array in memory (C order). Parameters ---------- a : array_like Input array. dtype : str or dtype object, optional Data-type of returned array. Returns ------- out : ndarray Contiguous array of same shape and content as `a`, with type `dtype` if specified. See Also -------- asfortranarray : Convert input to an ndarray with column-major memory order. require : Return an ndarray that satisfies requirements. ndarray.flags : Information about the memory layout of the array. Examples -------- >>> x = np.arange(6).reshape(2,3) >>> np.ascontiguousarray(x, dtype=np.float32) array([[ 0., 1., 2.], [ 3., 4., 5.]], dtype=float32) >>> x.flags['C_CONTIGUOUS'] True """ return array(a, dtype, copy=False, order='C', ndmin=1)
Example #24
Source File: numeric.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def asfortranarray(a, dtype=None): """ Return an array laid out in Fortran order in memory. Parameters ---------- a : array_like Input array. dtype : str or dtype object, optional By default, the data-type is inferred from the input data. Returns ------- out : ndarray The input `a` in Fortran, or column-major, order. See Also -------- ascontiguousarray : Convert input to a contiguous (C order) array. asanyarray : Convert input to an ndarray with either row or column-major memory order. require : Return an ndarray that satisfies requirements. ndarray.flags : Information about the memory layout of the array. Examples -------- >>> x = np.arange(6).reshape(2,3) >>> y = np.asfortranarray(x) >>> x.flags['F_CONTIGUOUS'] False >>> y.flags['F_CONTIGUOUS'] True """ return array(a, dtype, copy=False, order='F', ndmin=1)
Example #25
Source File: numeric.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def argwhere(a): """ Find the indices of array elements that are non-zero, grouped by element. Parameters ---------- a : array_like Input data. Returns ------- index_array : ndarray Indices of elements that are non-zero. Indices are grouped by element. See Also -------- where, nonzero Notes ----- ``np.argwhere(a)`` is the same as ``np.transpose(np.nonzero(a))``. The output of ``argwhere`` is not suitable for indexing arrays. For this purpose use ``where(a)`` instead. Examples -------- >>> x = np.arange(6).reshape(2,3) >>> x array([[0, 1, 2], [3, 4, 5]]) >>> np.argwhere(x>1) array([[0, 2], [1, 0], [1, 1], [1, 2]]) """ return transpose(nonzero(a))
Example #26
Source File: numeric.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def flatnonzero(a): """ Return indices that are non-zero in the flattened version of a. This is equivalent to a.ravel().nonzero()[0]. Parameters ---------- a : ndarray Input array. Returns ------- res : ndarray Output array, containing the indices of the elements of `a.ravel()` that are non-zero. See Also -------- nonzero : Return the indices of the non-zero elements of the input array. ravel : Return a 1-D array containing the elements of the input array. Examples -------- >>> x = np.arange(-2, 3) >>> x array([-2, -1, 0, 1, 2]) >>> np.flatnonzero(x) array([0, 1, 3, 4]) Use the indices of the non-zero elements as an index array to extract these elements: >>> x.ravel()[np.flatnonzero(x)] array([-2, -1, 1, 2]) """ return a.ravel().nonzero()[0]
Example #27
Source File: numeric.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def _validate_axis(axis, ndim, argname): try: axis = [operator.index(axis)] except TypeError: axis = list(axis) axis = [a + ndim if a < 0 else a for a in axis] if not builtins.all(0 <= a < ndim for a in axis): raise ValueError('invalid axis for this array in `%s` argument' % argname) if len(set(axis)) != len(axis): raise ValueError('repeated axis in `%s` argument' % argname) return axis
Example #28
Source File: numeric.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def array_str(a, max_line_width=None, precision=None, suppress_small=None): """ Return a string representation of the data in an array. The data in the array is returned as a single string. This function is similar to `array_repr`, the difference being that `array_repr` also returns information on the kind of array and its data type. Parameters ---------- a : ndarray Input array. max_line_width : int, optional Inserts newlines if text is longer than `max_line_width`. The default is, indirectly, 75. precision : int, optional Floating point precision. Default is the current printing precision (usually 8), which can be altered using `set_printoptions`. suppress_small : bool, optional Represent numbers "very close" to zero as zero; default is False. Very close is defined by precision: if the precision is 8, e.g., numbers smaller (in absolute value) than 5e-9 are represented as zero. See Also -------- array2string, array_repr, set_printoptions Examples -------- >>> np.array_str(np.arange(3)) '[0 1 2]' """ return array2string(a, max_line_width, precision, suppress_small, ' ', "", str)
Example #29
Source File: numeric.py From keras-lambda with MIT License | 5 votes |
def array_str(a, max_line_width=None, precision=None, suppress_small=None): """ Return a string representation of the data in an array. The data in the array is returned as a single string. This function is similar to `array_repr`, the difference being that `array_repr` also returns information on the kind of array and its data type. Parameters ---------- a : ndarray Input array. max_line_width : int, optional Inserts newlines if text is longer than `max_line_width`. The default is, indirectly, 75. precision : int, optional Floating point precision. Default is the current printing precision (usually 8), which can be altered using `set_printoptions`. suppress_small : bool, optional Represent numbers "very close" to zero as zero; default is False. Very close is defined by precision: if the precision is 8, e.g., numbers smaller (in absolute value) than 5e-9 are represented as zero. See Also -------- array2string, array_repr, set_printoptions Examples -------- >>> np.array_str(np.arange(3)) '[0 1 2]' """ return array2string(a, max_line_width, precision, suppress_small, ' ', "", str)
Example #30
Source File: numeric.py From keras-lambda with MIT License | 5 votes |
def _validate_axis(axis, ndim, argname): try: axis = [operator.index(axis)] except TypeError: axis = list(axis) axis = [a + ndim if a < 0 else a for a in axis] if not builtins.all(0 <= a < ndim for a in axis): raise ValueError('invalid axis for this array in `%s` argument' % argname) if len(set(axis)) != len(axis): raise ValueError('repeated axis in `%s` argument' % argname) return axis