當前位置: 首頁>>代碼示例>>Python>>正文


Python numpy.short方法代碼示例

本文整理匯總了Python中numpy.short方法的典型用法代碼示例。如果您正苦於以下問題:Python numpy.short方法的具體用法?Python numpy.short怎麽用?Python numpy.short使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在numpy的用法示例。


在下文中一共展示了numpy.short方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_reference_cycles

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import short [as 別名]
def test_reference_cycles(self):
        # related to gh-6511
        import ctypes

        # create array to work with
        # don't use int/long to avoid running into bpo-10746
        N = 100
        a = np.arange(N, dtype=np.short)

        # get pointer to array
        pnt = np.ctypeslib.as_ctypes(a)

        with np.testing.assert_no_gc_cycles():
            # decay the array above to a pointer to its first element
            newpnt = ctypes.cast(pnt, ctypes.POINTER(ctypes.c_short))
            # and construct an array using this data
            b = np.ctypeslib.as_array(newpnt, (N,))
            # now delete both, which should cleanup both objects
            del newpnt, b 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:21,代碼來源:test_ctypeslib.py

示例2: _unsigned_subtract

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import short [as 別名]
def _unsigned_subtract(a, b):
    """
    Subtract two values where a >= b, and produce an unsigned result

    This is needed when finding the difference between the upper and lower
    bound of an int16 histogram
    """
    # coerce to a single type
    signed_to_unsigned = {
        np.byte: np.ubyte,
        np.short: np.ushort,
        np.intc: np.uintc,
        np.int_: np.uint,
        np.longlong: np.ulonglong
    }
    dt = np.result_type(a, b)
    try:
        dt = signed_to_unsigned[dt.type]
    except KeyError:
        return np.subtract(a, b, dtype=dt)
    else:
        # we know the inputs are integers, and we are deliberately casting
        # signed to unsigned
        return np.subtract(a, b, casting='unsafe', dtype=dt) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:26,代碼來源:histograms.py

示例3: _unsigned_subtract

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import short [as 別名]
def _unsigned_subtract(a, b):
    """
    Subtract two values where a >= b, and produce an unsigned result

    This is needed when finding the difference between the upper and lower
    bound of an int16 histogram
    """
    # coerce to a single type
    signed_to_unsigned = {
        np.byte: np.ubyte,
        np.short: np.ushort,
        np.intc: np.uintc,
        np.int_: np.uint,
        np.longlong: np.ulonglong
    }
    dt = np.result_type(a, b)
    try:
        dt = signed_to_unsigned[dt.type]
    except KeyError:  # pragma: no cover
        return np.subtract(a, b, dtype=dt)
    else:
        # we know the inputs are integers, and we are deliberately casting
        # signed to unsigned
        return np.subtract(a, b, casting='unsafe', dtype=dt) 
開發者ID:mars-project,項目名稱:mars,代碼行數:26,代碼來源:histogram.py

示例4: makePathFromArrays

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import short [as 別名]
def makePathFromArrays(points, tags, contours):
    n_contours = len(contours)
    n_points = len(tags)
    assert len(points) >= n_points
    assert points.shape[1:] == (2,)
    if points.dtype != numpy.long:
        points = numpy.floor(points + [0.5, 0.5])
        points = points.astype(numpy.long)
    assert tags.dtype == numpy.byte
    assert contours.dtype == numpy.short
    path = objc.objc_object(
        c_void_p=_makePathFromArrays(
            n_contours,
            n_points,
            points.ctypes.data_as(FT_Vector_p),
            tags.ctypes.data_as(c_char_p),
            contours.ctypes.data_as(c_short_p)))
    # See comment in makePathFromOutline()
    path.release()
    return path 
開發者ID:justvanrossum,項目名稱:fontgoggles,代碼行數:22,代碼來源:makePathFromOutline.py

示例5: __init__

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import short [as 別名]
def __init__(self, glyphName, masterModel, masterPoints, contours, tags, components, getSubGlyph):
        self.model, masterPoints = masterModel.getSubModel(masterPoints)
        masterPoints = [numpy.array(pts, coordinateType) for pts in masterPoints]
        try:
            self.deltas = self.model.getDeltas(masterPoints)
        except ValueError:
            # outlines are not compatible, fall back to the default master
            print(f"Glyph '{glyphName}' is not interpolatable", file=sys.stderr)
            self.deltas = [masterPoints[self.model.reverseMapping[0]]]
        if components:
            self._contours = None
            self._tags = None
        else:
            self._contours = numpy.array(contours, numpy.short)
            self._tags = numpy.array(tags, numpy.byte)
        self.components = components
        self._getSubGlyph = getSubGlyph
        self.varLocation = {}
        self._points = None 
開發者ID:justvanrossum,項目名稱:fontgoggles,代碼行數:21,代碼來源:dsFont.py

示例6: adjust_color

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import short [as 別名]
def adjust_color(image_, channel, amount, inc):
    image = image_.copy()

    image = image.astype(np.short)

    t = image[:, :, channel]

    if inc is True:
        t += amount
    else:
        t -= amount

    image[:, :, channel] = t

    image = np.clip(image, 0, 255)

    image = image.astype(np.uint8)

    return image 
開發者ID:zerofox-oss,項目名稱:deepstar,代碼行數:21,代碼來源:cv.py

示例7: run

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import short [as 別名]
def run(self):
        self.logger.debug("Start to recording...")
        self.logger.debug("  Time = %s"%self.time)
        self.logger.debug("  Sample Rate = %s"%self.sr)
        self.start_time = time.time()
        pa=PyAudio()
        stream=pa.open(format = paInt16,channels=1, rate=self.sr,input=True, frames_per_buffer=self.frames_per_buffer)
        my_buf=[]
        count=0
        if self.time is None:
            total_count = 1e10
        else:
            total_count = self.time * self.sr / self.batch_num
        while count< total_count and self.__running.isSet():
            datawav = stream.read(self.batch_num, exception_on_overflow = True)
            datause = np.fromstring(datawav,dtype = np.short)
            for w in datause:
                self.buffer.put(w)
            count+=1
        stream.close() 
開發者ID:mhy12345,項目名稱:rcaudio,代碼行數:22,代碼來源:core_recorder.py

示例8: read_gzip_wave_file

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import short [as 別名]
def read_gzip_wave_file(filename):
    if (not os.path.isfile(filename)):
        raise ValueError("File does not exist")

    with gzip.open(filename, 'rb') as wav_file:
        with wave.open(wav_file, 'rb') as s:
            if (s.getnchannels() != 1):
                raise ValueError("Wave file should be mono")
            #if (s.getframerate() != 22050):
                #raise ValueError("Sampling rate of wave file should be 16000")

            strsig = s.readframes(s.getnframes())
            x = np.fromstring(strsig, np.short)
            fs = s.getframerate()
            s.close()

            return fs, x 
開發者ID:johnmartinsson,項目名稱:bird-species-classification,代碼行數:19,代碼來源:utils.py

示例9: read_wave_file

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import short [as 別名]
def read_wave_file(filename):
    """ Read a wave file from disk
    # Arguments
        filename : the name of the wave file
    # Returns
        (fs, x)  : (sampling frequency, signal)
    """
    if (not os.path.isfile(filename)):
        raise ValueError("File does not exist")

    s = wave.open(filename, 'rb')

    if (s.getnchannels() != 1):
        raise ValueError("Wave file should be mono")
    # if (s.getframerate() != 22050):
        # raise ValueError("Sampling rate of wave file should be 16000")

    strsig = s.readframes(s.getnframes())
    x = np.fromstring(strsig, np.short)
    fs = s.getframerate()
    s.close()

    x = x/32768.0

    return fs, x 
開發者ID:johnmartinsson,項目名稱:bird-species-classification,代碼行數:27,代碼來源:utils.py

示例10: read_wave_file_not_normalized

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import short [as 別名]
def read_wave_file_not_normalized(filename):
    """ Read a wave file from disk
    # Arguments
        filename : the name of the wave file
    # Returns
        (fs, x)  : (sampling frequency, signal)
    """
    if (not os.path.isfile(filename)):
        raise ValueError("File does not exist")

    s = wave.open(filename, 'rb')

    if (s.getnchannels() != 1):
        raise ValueError("Wave file should be mono")
    # if (s.getframerate() != 22050):
        # raise ValueError("Sampling rate of wave file should be 16000")

    strsig = s.readframes(s.getnframes())
    x = np.fromstring(strsig, np.short)
    fs = s.getframerate()
    s.close()

    return fs, x 
開發者ID:johnmartinsson,項目名稱:bird-species-classification,代碼行數:25,代碼來源:utils.py

示例11: read_wav_data

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import short [as 別名]
def read_wav_data(filename):
	'''
	讀取一個wav文件,返回聲音信號的時域譜矩陣和播放時間
	'''
	wav = wave.open(filename,"rb") # 打開一個wav格式的聲音文件流
	num_frame = wav.getnframes() # 獲取幀數
	num_channel=wav.getnchannels() # 獲取聲道數
	framerate=wav.getframerate() # 獲取幀速率
	num_sample_width=wav.getsampwidth() # 獲取實例的比特寬度,即每一幀的字節數
	str_data = wav.readframes(num_frame) # 讀取全部的幀
	wav.close() # 關閉流
	wave_data = np.fromstring(str_data, dtype = np.short) # 將聲音文件數據轉換為數組矩陣形式
	wave_data.shape = -1, num_channel # 按照聲道數將數組整形,單聲道時候是一列數組,雙聲道時候是兩列的矩陣
	wave_data = wave_data.T # 將矩陣轉置
	#wave_data = wave_data 
	return wave_data, framerate 
開發者ID:nl8590687,項目名稱:ASRT_SpeechRecognition,代碼行數:18,代碼來源:file_wav.py

示例12: test_signed_overflow_bounds

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import short [as 別名]
def test_signed_overflow_bounds(self):
        self.do_signed_overflow_bounds(np.byte)
        self.do_signed_overflow_bounds(np.short)
        self.do_signed_overflow_bounds(np.intc)
        self.do_signed_overflow_bounds(np.int_)
        self.do_signed_overflow_bounds(np.longlong) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:8,代碼來源:test_histograms.py

示例13: test_numpy

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import short [as 別名]
def test_numpy(self):
        """NumPy objects get serialized to readable JSON."""
        l = [
            np.float32(12.5),
            np.float64(2.0),
            np.float16(0.5),
            np.bool(True),
            np.bool(False),
            np.bool_(True),
            np.unicode_("hello"),
            np.byte(12),
            np.short(12),
            np.intc(-13),
            np.int_(0),
            np.longlong(100),
            np.intp(7),
            np.ubyte(12),
            np.ushort(12),
            np.uintc(13),
            np.ulonglong(100),
            np.uintp(7),
            np.int8(1),
            np.int16(3),
            np.int32(4),
            np.int64(5),
            np.uint8(1),
            np.uint16(3),
            np.uint32(4),
            np.uint64(5),
        ]
        l2 = [l, np.array([1, 2, 3])]
        roundtripped = loads(dumps(l2, cls=EliotJSONEncoder))
        self.assertEqual([l, [1, 2, 3]], roundtripped) 
開發者ID:itamarst,項目名稱:eliot,代碼行數:35,代碼來源:test_json.py


注:本文中的numpy.short方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。