Movatterモバイル変換


[0]ホーム

URL:


SciPy

numpy.memmap.getfield

memmap.getfield(dtype,offset=0)

Returns a field of the given array as a certain type.

A field is a view of the array data with a given data-type. The values inthe view are determined by the given type and the offset into the currentarray in bytes. The offset needs to be such that the view dtype fits in thearray dtype; for example an array of dtype complex128 has 16-byte elements.If taking a view with a 32-bit integer (4 bytes), the offset needs to bebetween 0 and 12 bytes.

Parameters:
dtype:str or dtype

The data type of the view. The dtype size of the view can not be largerthan that of the array itself.

offset:int

Number of bytes to skip before beginning the element view.

Examples

>>>x=np.diag([1.+1.j]*2)>>>x[1,1]=2+4.j>>>xarray([[ 1.+1.j,  0.+0.j],       [ 0.+0.j,  2.+4.j]])>>>x.getfield(np.float64)array([[ 1.,  0.],       [ 0.,  2.]])

By choosing an offset of 8 bytes we can select the complex part of thearray for our view:

>>>x.getfield(np.float64,offset=8)array([[ 1.,  0.],   [ 0.,  4.]])

Quick search

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

[8]ページ先頭

©2009-2025 Movatter.jp