本文整理汇总了Python中numpy.core.multiarray.array方法的典型用法代码示例。如果您正苦于以下问题:Python multiarray.array方法的具体用法?Python multiarray.array怎么用?Python multiarray.array使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy.core.multiarray
的用法示例。
在下文中一共展示了multiarray.array方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _create_J_without_numba
# 需要导入模块: from numpy.core import multiarray [as 别名]
# 或者: from numpy.core.multiarray import array [as 别名]
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
示例2: draw_pz
# 需要导入模块: from numpy.core import multiarray [as 别名]
# 或者: from numpy.core.multiarray import array [as 别名]
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])
示例3: ascontiguousarray
# 需要导入模块: from numpy.core import multiarray [as 别名]
# 或者: from numpy.core.multiarray import array [as 别名]
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)
示例4: asfortranarray
# 需要导入模块: from numpy.core import multiarray [as 别名]
# 或者: from numpy.core.multiarray import array [as 别名]
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)
示例5: argwhere
# 需要导入模块: from numpy.core import multiarray [as 别名]
# 或者: from numpy.core.multiarray import array [as 别名]
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))
示例6: flatnonzero
# 需要导入模块: from numpy.core import multiarray [as 别名]
# 或者: from numpy.core.multiarray import array [as 别名]
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]
示例7: _validate_axis
# 需要导入模块: from numpy.core import multiarray [as 别名]
# 或者: from numpy.core.multiarray import array [as 别名]
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
示例8: array_str
# 需要导入模块: from numpy.core import multiarray [as 别名]
# 或者: from numpy.core.multiarray import array [as 别名]
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)
示例9: identity
# 需要导入模块: from numpy.core import multiarray [as 别名]
# 或者: from numpy.core.multiarray import array [as 别名]
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)
示例10: test_var_corrected_two_pass
# 需要导入模块: from numpy.core import multiarray [as 别名]
# 或者: from numpy.core.multiarray import array [as 别名]
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)
示例11: test_var_textbook_one_pass
# 需要导入模块: from numpy.core import multiarray [as 别名]
# 或者: from numpy.core.multiarray import array [as 别名]
def test_var_textbook_one_pass(self):
assert_allclose(np.array(var(self.f, 'textbook one pass')).reshape(4,),
np.array([2, 2.25, 0.666667, 2]), rtol=1e-02)
assert_allclose(np.array(var(self.h, 'textbook one pass')).reshape(4,),
np.array([32, 9, 3.666667, 17]), rtol=1e-02)
assert_almost_equal(var(self.fa[:, 2], 'textbook one pass'), 0.66666666666666663)
示例12: test_var_standard_two_pass
# 需要导入模块: from numpy.core import multiarray [as 别名]
# 或者: from numpy.core.multiarray import array [as 别名]
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)
示例13: test_var_youngs_cramer
# 需要导入模块: from numpy.core import multiarray [as 别名]
# 或者: from numpy.core.multiarray import array [as 别名]
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)
示例14: test_stddev
# 需要导入模块: from numpy.core import multiarray [as 别名]
# 或者: from numpy.core.multiarray import array [as 别名]
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]))
示例15: test_errors
# 需要导入模块: from numpy.core import multiarray [as 别名]
# 或者: from numpy.core.multiarray import array [as 别名]
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)