Movatterモバイル変換


[0]ホーム

URL:


SciPy

numpy.ma.squeeze

numpy.ma.squeeze(a,axis=None)[source]

Remove single-dimensional entries from the shape of an array.

Parameters:

a : array_like

Input data.

axis : None or int or tuple of ints, optional

New in version 1.7.0.

Selects a subset of the single-dimensional entries in theshape. If an axis is selected with shape entry greater thanone, an error is raised.

Returns:

squeezed : ndarray

The input array, but with all or a subset of thedimensions of length 1 removed. This is alwaysa itselfor a view intoa.

Raises:

ValueError

Ifaxis is notNone, and an axis being squeezed is not of length 1

See also

expand_dims
The inverse operation, adding singleton dimensions
reshape
Insert, remove, and combine dimensions, and resize existing ones

Examples

>>>x=np.array([[[0],[1],[2]]])>>>x.shape(1, 3, 1)>>>np.squeeze(x).shape(3,)>>>np.squeeze(x,axis=0).shape(3, 1)>>>np.squeeze(x,axis=1).shapeTraceback (most recent call last):...ValueError:cannot select an axis to squeeze out which has size not equal to one>>>np.squeeze(x,axis=2).shape(1, 3)

Previous topic

numpy.ma.expand_dims

Next topic

numpy.ma.column_stack

  • © Copyright 2008-2009, The Scipy community.
  • Last updated on Jun 10, 2017.
  • Created usingSphinx 1.5.3.

[8]ページ先頭

©2009-2025 Movatter.jp