本文整理汇总了Python中numpy.core.multiarray.empty方法的典型用法代码示例。如果您正苦于以下问题:Python multiarray.empty方法的具体用法?Python multiarray.empty怎么用?Python multiarray.empty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy.core.multiarray
的用法示例。
在下文中一共展示了multiarray.empty方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ones
# 需要导入模块: from numpy.core import multiarray [as 别名]
# 或者: from numpy.core.multiarray import empty [as 别名]
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
示例2: empty
# 需要导入模块: from numpy.core import multiarray [as 别名]
# 或者: from numpy.core.multiarray import empty [as 别名]
def empty(shape, typecode='l', dtype=None):
dtype = convtypecode(typecode, dtype)
return mu.empty(shape, dtype)
示例3: _create_J_with_numba
# 需要导入模块: from numpy.core import multiarray [as 别名]
# 或者: from numpy.core.multiarray import empty [as 别名]
def _create_J_with_numba(Ybus, V, pvpq, pq, pvpq_lookup, npv, npq):
"""
:param Ybus:
:param V:
:param pvpq:
:param pq:
:param createJ:
:param pvpq_lookup:
:param npv:
:param npq:
:return:
"""
Ibus = zeros(len(V), dtype=complex128)
# create Jacobian from fast calc of dS_dV
dVm_x, dVa_x = dSbus_dV_numba_sparse(Ybus.data, Ybus.indptr, Ybus.indices, V, V / abs(V), Ibus)
# data in J, space preallocated is bigger than acutal Jx -> will be reduced later on
Jx = empty(len(dVm_x) * 4, dtype=float64)
# row pointer, dimension = pvpq.shape[0] + pq.shape[0] + 1
Jp = zeros(pvpq.shape[0] + pq.shape[0] + 1, dtype=int32)
# indices, same with the preallocated space (see Jx)
Jj = empty(len(dVm_x) * 4, dtype=int32)
# fill Jx, Jj and Jp
# createJ(dVm_x, dVa_x, Ybus.indptr, Ybus.indices, pvpq_lookup, pvpq, pq, Jx, Jj, Jp)
if len(pvpq) == len(pq):
create_J2(dVm_x, dVa_x, Ybus.indptr, Ybus.indices, pvpq_lookup, pvpq, pq, Jx, Jj, Jp)
else:
create_J(dVm_x, dVa_x, Ybus.indptr, Ybus.indices, pvpq_lookup, pvpq, pq, Jx, Jj, Jp)
# resize before generating the scipy sparse matrix
Jx.resize(Jp[-1], refcheck=False)
Jj.resize(Jp[-1], refcheck=False)
# generate scipy sparse matrix
dimJ = npv + npq + npq
J = sparse((Jx, Jj, Jp), shape=(dimJ, dimJ))
return J
示例4: zeros_like
# 需要导入模块: from numpy.core import multiarray [as 别名]
# 或者: from numpy.core.multiarray import empty [as 别名]
def zeros_like(a, dtype=None, order='K', subok=True):
"""
Return an array of zeros with the same shape and type as a given array.
Parameters
----------
a : array_like
The shape and data-type of `a` define these same attributes of
the returned array.
dtype : data-type, optional
Overrides the data type of the result.
.. versionadded:: 1.6.0
order : {'C', 'F', 'A', or 'K'}, optional
Overrides the memory layout of the result. 'C' means C-order,
'F' means F-order, 'A' means 'F' if `a` is Fortran contiguous,
'C' otherwise. 'K' means match the layout of `a` as closely
as possible.
.. versionadded:: 1.6.0
subok : bool, optional.
If True, then the newly created array will use the sub-class
type of 'a', otherwise it will be a base-class array. Defaults
to True.
Returns
-------
out : ndarray
Array of zeros with the same shape and type as `a`.
See Also
--------
ones_like : Return an array of ones with shape and type of input.
empty_like : Return an empty array with shape and type of input.
zeros : Return a new array setting values to zero.
ones : Return a new array setting values to one.
empty : Return a new uninitialized array.
Examples
--------
>>> x = np.arange(6)
>>> x = x.reshape((2, 3))
>>> x
array([[0, 1, 2],
[3, 4, 5]])
>>> np.zeros_like(x)
array([[0, 0, 0],
[0, 0, 0]])
>>> y = np.arange(3, dtype=np.float)
>>> y
array([ 0., 1., 2.])
>>> np.zeros_like(y)
array([ 0., 0., 0.])
"""
res = empty_like(a, dtype=dtype, order=order, subok=subok)
# needed instead of a 0 to get same result as zeros for for string dtypes
z = zeros(1, dtype=res.dtype)
multiarray.copyto(res, z, casting='unsafe')
return res
示例5: ones
# 需要导入模块: from numpy.core import multiarray [as 别名]
# 或者: from numpy.core.multiarray import empty [as 别名]
def ones(shape, dtype=None, order='C'):
"""
Return a new array of given shape and type, filled with ones.
Parameters
----------
shape : int or sequence of ints
Shape of the new array, e.g., ``(2, 3)`` or ``2``.
dtype : data-type, optional
The desired data-type for the array, e.g., `numpy.int8`. Default is
`numpy.float64`.
order : {'C', 'F'}, optional
Whether to store multidimensional data in C- or Fortran-contiguous
(row- or column-wise) order in memory.
Returns
-------
out : ndarray
Array of ones with the given shape, dtype, and order.
See Also
--------
zeros, ones_like
Examples
--------
>>> np.ones(5)
array([ 1., 1., 1., 1., 1.])
>>> np.ones((5,), dtype=np.int)
array([1, 1, 1, 1, 1])
>>> np.ones((2, 1))
array([[ 1.],
[ 1.]])
>>> s = (2,2)
>>> np.ones(s)
array([[ 1., 1.],
[ 1., 1.]])
"""
a = empty(shape, dtype, order)
multiarray.copyto(a, 1, casting='unsafe')
return a
示例6: ones_like
# 需要导入模块: from numpy.core import multiarray [as 别名]
# 或者: from numpy.core.multiarray import empty [as 别名]
def ones_like(a, dtype=None, order='K', subok=True):
"""
Return an array of ones with the same shape and type as a given array.
Parameters
----------
a : array_like
The shape and data-type of `a` define these same attributes of
the returned array.
dtype : data-type, optional
Overrides the data type of the result.
.. versionadded:: 1.6.0
order : {'C', 'F', 'A', or 'K'}, optional
Overrides the memory layout of the result. 'C' means C-order,
'F' means F-order, 'A' means 'F' if `a` is Fortran contiguous,
'C' otherwise. 'K' means match the layout of `a` as closely
as possible.
.. versionadded:: 1.6.0
subok : bool, optional.
If True, then the newly created array will use the sub-class
type of 'a', otherwise it will be a base-class array. Defaults
to True.
Returns
-------
out : ndarray
Array of ones with the same shape and type as `a`.
See Also
--------
zeros_like : Return an array of zeros with shape and type of input.
empty_like : Return an empty array with shape and type of input.
zeros : Return a new array setting values to zero.
ones : Return a new array setting values to one.
empty : Return a new uninitialized array.
Examples
--------
>>> x = np.arange(6)
>>> x = x.reshape((2, 3))
>>> x
array([[0, 1, 2],
[3, 4, 5]])
>>> np.ones_like(x)
array([[1, 1, 1],
[1, 1, 1]])
>>> y = np.arange(3, dtype=np.float)
>>> y
array([ 0., 1., 2.])
>>> np.ones_like(y)
array([ 1., 1., 1.])
"""
res = empty_like(a, dtype=dtype, order=order, subok=subok)
multiarray.copyto(res, 1, casting='unsafe')
return res
示例7: full
# 需要导入模块: from numpy.core import multiarray [as 别名]
# 或者: from numpy.core.multiarray import empty [as 别名]
def full(shape, fill_value, dtype=None, order='C'):
"""
Return a new array of given shape and type, filled with `fill_value`.
Parameters
----------
shape : int or sequence of ints
Shape of the new array, e.g., ``(2, 3)`` or ``2``.
fill_value : scalar
Fill value.
dtype : data-type, optional
The desired data-type for the array, e.g., `np.int8`. Default
is `float`, but will change to `np.array(fill_value).dtype` in a
future release.
order : {'C', 'F'}, optional
Whether to store multidimensional data in C- or Fortran-contiguous
(row- or column-wise) order in memory.
Returns
-------
out : ndarray
Array of `fill_value` with the given shape, dtype, and order.
See Also
--------
zeros_like : Return an array of zeros with shape and type of input.
ones_like : Return an array of ones with shape and type of input.
empty_like : Return an empty array with shape and type of input.
full_like : Fill an array with shape and type of input.
zeros : Return a new array setting values to zero.
ones : Return a new array setting values to one.
empty : Return a new uninitialized array.
Examples
--------
>>> np.full((2, 2), np.inf)
array([[ inf, inf],
[ inf, inf]])
>>> np.full((2, 2), 10, dtype=np.int)
array([[10, 10],
[10, 10]])
"""
a = empty(shape, dtype, order)
if dtype is None and array(fill_value).dtype != a.dtype:
warnings.warn(
"in the future, full({0}, {1!r}) will return an array of {2!r}".
format(shape, fill_value, array(fill_value).dtype), FutureWarning)
multiarray.copyto(a, fill_value, casting='unsafe')
return a
示例8: full_like
# 需要导入模块: from numpy.core import multiarray [as 别名]
# 或者: from numpy.core.multiarray import empty [as 别名]
def full_like(a, fill_value, dtype=None, order='K', subok=True):
"""
Return a full array with the same shape and type as a given array.
Parameters
----------
a : array_like
The shape and data-type of `a` define these same attributes of
the returned array.
fill_value : scalar
Fill value.
dtype : data-type, optional
Overrides the data type of the result.
order : {'C', 'F', 'A', or 'K'}, optional
Overrides the memory layout of the result. 'C' means C-order,
'F' means F-order, 'A' means 'F' if `a` is Fortran contiguous,
'C' otherwise. 'K' means match the layout of `a` as closely
as possible.
subok : bool, optional.
If True, then the newly created array will use the sub-class
type of 'a', otherwise it will be a base-class array. Defaults
to True.
Returns
-------
out : ndarray
Array of `fill_value` with the same shape and type as `a`.
See Also
--------
zeros_like : Return an array of zeros with shape and type of input.
ones_like : Return an array of ones with shape and type of input.
empty_like : Return an empty array with shape and type of input.
zeros : Return a new array setting values to zero.
ones : Return a new array setting values to one.
empty : Return a new uninitialized array.
full : Fill a new array.
Examples
--------
>>> x = np.arange(6, dtype=np.int)
>>> np.full_like(x, 1)
array([1, 1, 1, 1, 1, 1])
>>> np.full_like(x, 0.1)
array([0, 0, 0, 0, 0, 0])
>>> np.full_like(x, 0.1, dtype=np.double)
array([ 0.1, 0.1, 0.1, 0.1, 0.1, 0.1])
>>> np.full_like(x, np.nan, dtype=np.double)
array([ nan, nan, nan, nan, nan, nan])
>>> y = np.arange(6, dtype=np.double)
>>> np.full_like(y, 0.1)
array([ 0.1, 0.1, 0.1, 0.1, 0.1, 0.1])
"""
res = empty_like(a, dtype=dtype, order=order, subok=subok)
multiarray.copyto(res, fill_value, casting='unsafe')
return res