python numpy ones.like()(返回形状与类型与给定数组相同的数组)
生活随笔
收集整理的這篇文章主要介紹了
python numpy ones.like()(返回形状与类型与给定数组相同的数组)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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_likeThe shape and data-type of `a` define these same attributes ofthe returned array.a的形狀和數據類型定義了返回數組的這些相同屬性。dtype : data-type, optionalOverrides the data type of the result.覆蓋結果的數據類型。.. versionadded:: 1.6.0order : {'C', 'F', 'A', or 'K'}, optionalOverrides 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 closelyas possible.覆蓋結果的內存布局。 “ C”表示C階,“ F”表示F階,如果“ a”是Fortran連續的,則“ A”表示“ F”,否則為“ C”。 “ K”表示盡可能匹配“ a”的布局。.. versionadded:: 1.6.0subok : bool, optional.If True, then the newly created array will use the sub-classtype of 'a', otherwise it will be a base-class array. Defaultsto True.如果為True,則新創建的數組將使用'a'的子類類型,否則它將是基類數組。 默認為True。Returns-------out : ndarrayArray of ones with the same shape and type as `a`.與a形狀和類型相同的數組。See Also--------empty_like : Return an empty array with shape and type of input.zeros_like : Return an array of zeros with shape and type of input.full_like : Return a new array with shape of input filled with value.ones : Return a new array setting values to one.Examples-------->>> x = np.arange(6)>>> x = x.reshape((2, 3))>>> xarray([[0, 1, 2],[3, 4, 5]])>>> np.ones_like(x)array([[1, 1, 1],[1, 1, 1]])>>> y = np.arange(3, dtype=float)>>> yarray([ 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
總結
以上是生活随笔為你收集整理的python numpy ones.like()(返回形状与类型与给定数组相同的数组)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python pass 占位符 占位语句
- 下一篇: numpy dot()函数(两个数组的点