本文整理汇总了Python中numpy.core.numeric.shape函数的典型用法代码示例。如果您正苦于以下问题:Python shape函数的具体用法?Python shape怎么用?Python shape使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了shape函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _replace_zero_by_x_arrays
def _replace_zero_by_x_arrays(sub_arys):
for i in range(len(sub_arys)):
if len(_nx.shape(sub_arys[i])) == 0:
sub_arys[i] = _nx.array([])
elif _nx.sometrue(_nx.equal(_nx.shape(sub_arys[i]),0)):
sub_arys[i] = _nx.array([])
return sub_arys
开发者ID:BlackEarth,项目名称:portable-python-win32,代码行数:7,代码来源:shape_base.py
示例2: _replace_zero_by_x_arrays
def _replace_zero_by_x_arrays(sub_arys):
for i in range(len(sub_arys)):
if _nx.ndim(sub_arys[i]) == 0:
sub_arys[i] = _nx.empty(0, dtype=sub_arys[i].dtype)
elif _nx.sometrue(_nx.equal(_nx.shape(sub_arys[i]), 0)):
sub_arys[i] = _nx.empty(0, dtype=sub_arys[i].dtype)
return sub_arys
开发者ID:Juanlu001,项目名称:numpy,代码行数:7,代码来源:shape_base.py
示例3: vsplit
def vsplit(ary,indices_or_sections):
"""
Split an array into multiple sub-arrays vertically (row-wise).
Please refer to the ``split`` documentation. ``vsplit`` is equivalent
to ``split`` with `axis=0` (default), the array is always split along the
first axis regardless of the array dimension.
See Also
--------
split : Split an array into multiple sub-arrays of equal size.
Examples
--------
>>> x = np.arange(16.0).reshape(4, 4)
>>> x
array([[ 0., 1., 2., 3.],
[ 4., 5., 6., 7.],
[ 8., 9., 10., 11.],
[ 12., 13., 14., 15.]])
>>> np.vsplit(x, 2)
[array([[ 0., 1., 2., 3.],
[ 4., 5., 6., 7.]]),
array([[ 8., 9., 10., 11.],
[ 12., 13., 14., 15.]])]
>>> np.vsplit(x, np.array([3, 6]))
[array([[ 0., 1., 2., 3.],
[ 4., 5., 6., 7.],
[ 8., 9., 10., 11.]]),
array([[ 12., 13., 14., 15.]]),
array([], dtype=float64)]
With a higher dimensional array the split is still along the first axis.
>>> x = np.arange(8.0).reshape(2, 2, 2)
>>> x
array([[[ 0., 1.],
[ 2., 3.]],
[[ 4., 5.],
[ 6., 7.]]])
>>> np.vsplit(x, 2)
[array([[[ 0., 1.],
[ 2., 3.]]]),
array([[[ 4., 5.],
[ 6., 7.]]])]
"""
if len(_nx.shape(ary)) < 2:
raise ValueError('vsplit only works on arrays of 2 or more dimensions')
return split(ary,indices_or_sections,0)
开发者ID:BlackEarth,项目名称:portable-python-win32,代码行数:50,代码来源:shape_base.py
示例4: dsplit
def dsplit(ary,indices_or_sections):
"""
Split array into multiple sub-arrays along the 3rd axis (depth).
Please refer to the `split` documentation. `dsplit` is equivalent
to `split` with ``axis=2``, the array is always split along the third
axis provided the array dimension is greater than or equal to 3.
See Also
--------
split : Split an array into multiple sub-arrays of equal size.
Examples
--------
>>> x = np.arange(16.0).reshape(2, 2, 4)
>>> x
array([[[ 0., 1., 2., 3.],
[ 4., 5., 6., 7.]],
[[ 8., 9., 10., 11.],
[ 12., 13., 14., 15.]]])
>>> np.dsplit(x, 2)
[array([[[ 0., 1.],
[ 4., 5.]],
[[ 8., 9.],
[ 12., 13.]]]),
array([[[ 2., 3.],
[ 6., 7.]],
[[ 10., 11.],
[ 14., 15.]]])]
>>> np.dsplit(x, np.array([3, 6]))
[array([[[ 0., 1., 2.],
[ 4., 5., 6.]],
[[ 8., 9., 10.],
[ 12., 13., 14.]]]),
array([[[ 3.],
[ 7.]],
[[ 11.],
[ 15.]]]),
array([], dtype=float64)]
"""
if len(_nx.shape(ary)) < 3:
raise ValueError('vsplit only works on arrays of 3 or more dimensions')
return split(ary,indices_or_sections,2)
开发者ID:BlackEarth,项目名称:portable-python-win32,代码行数:44,代码来源:shape_base.py
示例5: hsplit
def hsplit(ary,indices_or_sections):
""" Split ary into multiple columns of sub-arrays
Description:
Split a single array into multiple sub arrays. The array is
divided into groups of columns. If indices_or_sections is
an integer, ary is divided into that many equally sized sub arrays.
If it is impossible to make the sub-arrays equally sized, the
operation throws a ValueError exception. See array_split and
split for other options on indices_or_sections.
Arguments:
ary -- N-D array.
Array to be divided into sub-arrays.
indices_or_sections -- integer or 1D array.
If integer, defines the number of (close to) equal sized
sub-arrays. If it is a 1D array of sorted indices, it
defines the indexes at which ary is divided. Any empty
list results in a single sub-array equal to the original
array.
Returns:
sequence of sub-arrays. The returned arrays have the same
number of dimensions as the input array.
Related:
hstack, split, array_split, vsplit, dsplit.
Examples:
>>> import numpy
>>> a= array((1,2,3,4))
>>> numpy.hsplit(a,2)
[array([1, 2]), array([3, 4])]
>>> a = array([[1,2,3,4],[1,2,3,4]])
>>> hsplit(a,2)
[array([[1, 2],
[1, 2]]), array([[3, 4],
[3, 4]])]
"""
if len(_nx.shape(ary)) == 0:
raise ValueError, 'hsplit only works on arrays of 1 or more dimensions'
if len(ary.shape) > 1:
return split(ary,indices_or_sections,1)
else:
return split(ary,indices_or_sections,0)
开发者ID:8848,项目名称:Pymol-script-repo,代码行数:42,代码来源:shape_base.py
示例6: vsplit
def vsplit(ary,indices_or_sections):
""" Split ary into multiple rows of sub-arrays
Description:
Split a single array into multiple sub arrays. The array is
divided into groups of rows. If indices_or_sections is
an integer, ary is divided into that many equally sized sub arrays.
If it is impossible to make the sub-arrays equally sized, the
operation throws a ValueError exception. See array_split and
split for other options on indices_or_sections.
Arguments:
ary -- N-D array.
Array to be divided into sub-arrays.
indices_or_sections -- integer or 1D array.
If integer, defines the number of (close to) equal sized
sub-arrays. If it is a 1D array of sorted indices, it
defines the indexes at which ary is divided. Any empty
list results in a single sub-array equal to the original
array.
Returns:
sequence of sub-arrays. The returned arrays have the same
number of dimensions as the input array.
Caveats:
How should we handle 1D arrays here? I am currently raising
an error when I encounter them. Any better approach?
Should we reduce the returned array to their minium dimensions
by getting rid of any dimensions that are 1?
Related:
vstack, split, array_split, hsplit, dsplit.
Examples:
import numpy
>>> a = array([[1,2,3,4],
... [1,2,3,4]])
>>> numpy.vsplit(a,2)
[array([[1, 2, 3, 4]]), array([[1, 2, 3, 4]])]
"""
if len(_nx.shape(ary)) < 2:
raise ValueError, 'vsplit only works on arrays of 2 or more dimensions'
return split(ary,indices_or_sections,0)
开发者ID:8848,项目名称:Pymol-script-repo,代码行数:41,代码来源:shape_base.py
示例7: dsplit
def dsplit(ary,indices_or_sections):
""" Split ary into multiple sub-arrays along the 3rd axis (depth)
Description:
Split a single array into multiple sub arrays. The array is
divided into groups along the 3rd axis. If indices_or_sections is
an integer, ary is divided into that many equally sized sub arrays.
If it is impossible to make the sub-arrays equally sized, the
operation throws a ValueError exception. See array_split and
split for other options on indices_or_sections.
Arguments:
ary -- N-D array.
Array to be divided into sub-arrays.
indices_or_sections -- integer or 1D array.
If integer, defines the number of (close to) equal sized
sub-arrays. If it is a 1D array of sorted indices, it
defines the indexes at which ary is divided. Any empty
list results in a single sub-array equal to the original
array.
Returns:
sequence of sub-arrays. The returned arrays have the same
number of dimensions as the input array.
Caveats:
See vsplit caveats.
Related:
dstack, split, array_split, hsplit, vsplit.
Examples:
>>> a = array([[[1,2,3,4],[1,2,3,4]]])
>>> dsplit(a,2)
[array([[[1, 2],
[1, 2]]]), array([[[3, 4],
[3, 4]]])]
"""
if len(_nx.shape(ary)) < 3:
raise ValueError, 'vsplit only works on arrays of 3 or more dimensions'
return split(ary,indices_or_sections,2)
开发者ID:8848,项目名称:Pymol-script-repo,代码行数:37,代码来源:shape_base.py
示例8: hsplit
def hsplit(ary,indices_or_sections):
"""
Split an array into multiple sub-arrays horizontally (column-wise).
Please refer to the `split` documentation. `hsplit` is equivalent
to `split` with ``axis=1``, the array is always split along the second
axis regardless of the array dimension.
See Also
--------
split : Split an array into multiple sub-arrays of equal size.
Examples
--------
>>> x = np.arange(16.0).reshape(4, 4)
>>> x
array([[ 0., 1., 2., 3.],
[ 4., 5., 6., 7.],
[ 8., 9., 10., 11.],
[ 12., 13., 14., 15.]])
>>> np.hsplit(x, 2)
[array([[ 0., 1.],
[ 4., 5.],
[ 8., 9.],
[ 12., 13.]]),
array([[ 2., 3.],
[ 6., 7.],
[ 10., 11.],
[ 14., 15.]])]
>>> np.hsplit(x, np.array([3, 6]))
[array([[ 0., 1., 2.],
[ 4., 5., 6.],
[ 8., 9., 10.],
[ 12., 13., 14.]]),
array([[ 3.],
[ 7.],
[ 11.],
[ 15.]]),
array([], dtype=float64)]
With a higher dimensional array the split is still along the second axis.
>>> x = np.arange(8.0).reshape(2, 2, 2)
>>> x
array([[[ 0., 1.],
[ 2., 3.]],
[[ 4., 5.],
[ 6., 7.]]])
>>> np.hsplit(x, 2)
[array([[[ 0., 1.]],
[[ 4., 5.]]]),
array([[[ 2., 3.]],
[[ 6., 7.]]])]
"""
if len(_nx.shape(ary)) == 0:
raise ValueError('hsplit only works on arrays of 1 or more dimensions')
if len(ary.shape) > 1:
return split(ary,indices_or_sections,1)
else:
return split(ary,indices_or_sections,0)
开发者ID:BlackEarth,项目名称:portable-python-win32,代码行数:61,代码来源:shape_base.py
注:本文中的numpy.core.numeric.shape函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论