Movatterモバイル変換


[0]ホーム

URL:


SciPy

numpy.ndarray.shape

ndarray.shape

Tuple of array dimensions.

The shape property is usually used to get the current shape of an array,but may also be used to reshape the array in-place by assigning a tuple ofarray dimensions to it. As withnumpy.reshape, one of the new shapedimensions can be -1, in which case its value is inferred from the size ofthe array and the remaining dimensions. Reshaping an array in-place willfail if a copy is required.

See also

numpy.reshape
similar function
ndarray.reshape
similar method

Examples

>>>x=np.array([1,2,3,4])>>>x.shape(4,)>>>y=np.zeros((2,3,4))>>>y.shape(2, 3, 4)>>>y.shape=(3,8)>>>yarray([[ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.]])>>>y.shape=(3,6)Traceback (most recent call last):  File"<stdin>", line1, in<module>ValueError:total size of new array must be unchanged>>>np.zeros((4,2))[::2].shape=(-1,)Traceback (most recent call last):  File"<stdin>", line1, in<module>AttributeError:incompatible shape for a non-contiguous array

Previous topic

numpy.ndarray.flags

Next topic

numpy.ndarray.strides

Quick search

  • © Copyright 2008-2018, The SciPy community.
  • Last updated on Jul 24, 2018.
  • Created usingSphinx 1.6.6.

[8]ページ先頭

©2009-2025 Movatter.jp