• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python numpy.fromstring函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中numpy.fromstring函数的典型用法代码示例。如果您正苦于以下问题:Python fromstring函数的具体用法?Python fromstring怎么用?Python fromstring使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了fromstring函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: __init__

    def __init__(self, source):
        """Reader MEG data from texfiles or file-like objects.

        Parameters
        ----------
        source : str or file-like
          Strings are assumed to be filenames (with `.gz` suffix
          compressed), while all other object types are treated as file-like
          objects.
        """
        self.ntimepoints = None
        self.timepoints = None
        self.nsamples = None
        self.channelids = []
        self.data = []
        self.samplingrate = None

        # open textfiles
        if isinstance(source, str):
            if source.endswith('.gz'):
                externals.exists('gzip', raise_=True)
                import gzip
                source = gzip.open(source, 'r')
            else:
                source = open(source, 'r')

        # read file
        for line in source:
            # split ID
            colon = line.find(':')

            # ignore lines without id
            if colon == -1:
                continue

            id = line[:colon]
            data = line[colon+1:].strip()
            if id == 'Sample Number':
                timepoints = np.fromstring(data, dtype=int, sep='\t')
                # one more as it starts with zero
                self.ntimepoints = int(timepoints.max()) + 1
                self.nsamples = int(len(timepoints) / self.ntimepoints)
            elif id == 'Time':
                self.timepoints = np.fromstring(data,
                                               dtype=float,
                                               count=self.ntimepoints,
                                               sep='\t')
                self.samplingrate = self.ntimepoints \
                    / (self.timepoints[-1] - self.timepoints[0])
            else:
                # load data
                self.data.append(
                    np.fromstring(data, dtype=float, sep='\t').reshape(
                        self.nsamples, self.ntimepoints))
                # store id
                self.channelids.append(id)

        # reshape data from (channels x samples x timepoints) to
        # (samples x chanels x timepoints)
        self.data = np.swapaxes(np.array(self.data), 0, 1)
开发者ID:B-Rich,项目名称:PyMVPA,代码行数:60,代码来源:meg.py


示例2: get_stream

	def get_stream(self, chan, time_interval):
		self.fpga.write_int('pps_start', 1)
		#self.phases = np.empty((len(self.freqs),Npackets))
		Npackets = np.int(time_interval * self.accum_freq)
		Is = np.empty(Npackets)
		Qs = np.empty(Npackets)
		phases = np.empty(Npackets)
		count = 0
		while count < Npackets:
			packet = self.s.recv(8192 + 42) # total number of bytes including 42 byte header
			header = np.fromstring(packet[:42],dtype = '<B')
			roach_mac = header[6:12]
			filter_on = np.array([2, 68, 1, 2, 13, 33])
			if np.array_equal(roach_mac,filter_on):
				data = np.fromstring(packet[42:],dtype = '<i').astype('float')
				data /= 2.0**17
				data /= (self.accum_len/512.)
				ts = (np.fromstring(packet[-4:],dtype = '<i').astype('float')/ self.fpga_samp_freq)*1.0e3 # ts in ms
				# To stream one channel, make chan an argument
				if (chan % 2) > 0:
					I = data[1024 + ((chan - 1) / 2)]	
					Q = data[1536 + ((chan - 1) /2)]	
				else:
					I = data[0 + (chan/2)]	
					Q = data[512 + (chan/2)]	
				phase = np.arctan2([Q],[I])
				Is[count]=I
				Qs[count]=Q
				phases[count]=phase
			else:
				continue
			count += 1
		return Is, Qs, phases
开发者ID:braddober,项目名称:blastfirmware,代码行数:33,代码来源:blastfirmware_dirfile.py


示例3: get_UDP

        def get_UDP(self, Npackets, LO_freq, skip_packets=2, channels = None):
		#Npackets = np.int(time_interval * self.accum_freq)
		I_buffer = np.empty((Npackets + skip_packets, len(channels)))
		Q_buffer = np.empty((Npackets + skip_packets, len(channels)))
		self.fpga.write_int('pps_start', 1)
		count = 0
		while count < Npackets + skip_packets:
			packet = self.s.recv(8192) 
			data = np.fromstring(packet,dtype = '<i').astype('float')
			data /= 2.0**17
			data /= (self.accum_len/512.)
			ts = (np.fromstring(packet[-4:],dtype = '<i').astype('float')/ self.fpga_samp_freq)*1.0e3 # ts in ms
			odd_chan = channels[1::2]
			even_chan = channels[0::2]
			I_odd = data[1024 + ((odd_chan - 1) / 2)]	
			Q_odd = data[1536 + ((odd_chan - 1) /2)]	
			I_even = data[0 + (even_chan/2)]	
			Q_even = data[512 + (even_chan/2)]	
			even_phase = np.arctan2(Q_even,I_even)
			odd_phase = np.arctan2(Q_odd,I_odd)
			if len(channels) % 2 > 0:
				I = np.hstack(zip(I_even[:len(I_odd)], I_odd))
				Q = np.hstack(zip(Q_even[:len(Q_odd)], Q_odd))
				I = np.hstack((I, I_even[-1]))	
				Q = np.hstack((Q, Q_even[-1]))	
				I_buffer[count] = I
				Q_buffer[count] = Q
			else:
				I = np.hstack(zip(I_even, I_odd))
				Q = np.hstack(zip(Q_even, Q_odd))
				I_buffer[count] = I
				Q_buffer[count] = Q
				
			count += 1
		return I_buffer[skip_packets:],Q_buffer[skip_packets:]
开发者ID:braddober,项目名称:blastfirmware,代码行数:35,代码来源:blastfirmware_dirfile.py


示例4: send

def send(cloudstream, data, timeout = 0.25):
    sock = cloudstream.socket
    #print data.shape
    data = data.reshape(-1, 1)
    #print data.shape
    sock.send("upload")
    alive = time.time()
    while time.time() - alive < timeout:
        try:
            msg = sock.recv_multipart(flags = zmq.DONTWAIT)
            pstart, size = msg
            pstart = np.fromstring(pstart, "int32", 1)[0] * 3
            size = np.fromstring(size, "int32", 1)[0] * 3
            pend = pstart + size
            #print "sending", pstart, pend
            #print("sending", pstart, pend, data.shape[0])
            if pstart < 0:
                return True
            elif pstart <= data.shape[0]:
                #print data.shape, data.dtype, pstart, pend
                #print "subdata", data[pstart:min(data.shape[0], pend)].shape
                chunk = data[pstart:min(data.shape[0], pend)].tostring()
                #print len(chunk)
                sock.send(chunk)
            alive = time.time()
        except zmq.error.Again:
            continue
    print "Connection timeout"
    return False
开发者ID:gvsurenderreddy,项目名称:cloudstreamer,代码行数:29,代码来源:cstream.py


示例5: _read_variable_data

     def _read_variable_data(self, raw_data):

        """ Read the raw data and set the variable values. """

        if('real' in self.flags):
            number_of_columns = self.number_of_variables
        elif('complex' in self.flags):
            number_of_columns = 2*self.number_of_variables
        else:
            raise NotImplementedError

        if('Transient' in self.plot_name): #Tran
            number_of_columns = self.number_of_variables+1
            input_data = np.fromstring(raw_data, count=number_of_columns*self.number_of_points, dtype='float32')
            input_data = input_data.reshape((self.number_of_points, number_of_columns))
            input_data = input_data.transpose()
            time = input_data [0:2]
            tmpdata= time.transpose().flatten().tostring()
            time=np.fromstring(tmpdata, count=self.number_of_points, dtype='float64')
            time=np.absolute(time)
            input_data = input_data [1:]
            input_data[0]=time
        else:
            input_data = np.fromstring(raw_data, count=number_of_columns*self.number_of_points, dtype='float64')
            input_data = input_data.reshape((self.number_of_points, number_of_columns))
            input_data = input_data.transpose()
        #input_data = input_data [1:]
        #np.savetxt('raw.txt', input_data)
        if 'complex' in self.flags:
            raw_data = input_data
            input_data = np.array(raw_data[0::2], dtype='complex64')
            input_data.imag = raw_data[1::2]
        for variable in self.variables.values():
            variable.data = input_data[variable.index]
开发者ID:danielvilas,项目名称:PySpice-Library,代码行数:34,代码来源:LTSpiceServerXVII.py


示例6: decode_req

def decode_req(metadata, data, data2):
    a, b, iterations, l, w, array_dtype, l2, w2, array_dtype2 = metadata.split('|')
    syn0 = np.fromstring(data, dtype=array_dtype)
    syn0 = syn0.reshape(int(l), int(w))
    syn1 = np.fromstring(data2, dtype=array_dtype2).reshape(int(l2), int(w2))
    conf = (syn0, syn1)
    return int(a), int(b), int(iterations), conf
开发者ID:alcides,项目名称:bigdatagpunn,代码行数:7,代码来源:queue.py


示例7: getcorr

 def getcorr(self):
     self.u.write_int('corr0_ctrl',0)
     self.u.write_int('corr1_ctrl',0)
     self.u.write_int('corr0_ctrl',1)
     self.u.write_int('corr1_ctrl',1)
     done = False
     while not done:
         a = self.u.read_int('corr0_addr')
         b = self.u.read_int('corr1_addr')
         if a > 0 and b > 0:
             done = True
     depth = 36*3*self.nch/4
     l0 = np.fromstring(self.u.read('corr0_bram_lsb',depth*4),dtype='int16').byteswap().astype('float')
     l0 = l0[::2] + l0[1::2]*1j
     m0 = np.fromstring(self.u.read('corr0_bram_msb',depth*4),dtype='int16').byteswap().astype('float')
     m0 = m0[::2] + m0[1::2]*1j
     l1 = np.fromstring(self.u.read('corr1_bram_lsb',depth*4),dtype='int16').byteswap().astype('float')
     l1 = l1[::2] + l1[1::2]*1j
     m1 = np.fromstring(self.u.read('corr1_bram_msb',depth*4),dtype='int16').byteswap().astype('float')
     m1 = m1[::2] + m1[1::2]*1j
     
     c = np.zeros((3,36,self.nch),dtype='complex')
     for k in range(36):
         s = np.zeros((3*self.nch,),dtype='complex')
         s[0::4] = m0[k::36]
         s[1::4] = l0[k::36]
         s[2::4] = m1[k::36]
         s[3::4] = l1[k::36]
         for t in range(3):
             c[t,k,:] = s[(t*self.nch):((t+1)*self.nch)]
     return c
开发者ID:caseyjlaw,项目名称:misc,代码行数:31,代码来源:poco_observing.py


示例8: read_MSR_depth_ims

def read_MSR_depth_ims(depth_file, resize='VGA'):
	''' Extracts depth images and masks from the MSR Daily Activites dataset
	---Parameters---
	depth_file : filename for set of depth images (.bin file)
	'''

	file_ = open(depth_file, 'rb')

	''' Get header info '''
	frames = np.fromstring(file_.read(4), dtype=np.int32)[0]
	cols = np.fromstring(file_.read(4), dtype=np.int32)[0]
	rows = np.fromstring(file_.read(4), dtype=np.int32)[0]

	''' Get depth/mask image data '''
	data = file_.read()

	'''
	Depth images and mask images are stored together per row.
	Thus we need to extract each row of size n_cols+n_rows
	'''
	dt = np.dtype([('depth', np.int32, cols), ('mask', np.uint8, cols)])

	''' raw -> usable images '''
	frame_data = np.fromstring(data, dtype=dt)
	depthIms = frame_data['depth'].astype(np.uint16).reshape([frames, rows, cols])
	maskIms = frame_data['mask'].astype(np.uint16).reshape([frames, rows, cols])

	if resize == 'VGA':
		# embed()
		depthIms = np.dstack([cv2.resize(depthIms[d,:,:], (640,480)) for d in xrange(len(depthIms))])
		maskIms = np.dstack([cv2.resize(maskIms[d,:,:], (640,480)) for d in xrange(len(maskIms))])

	return depthIms, maskIms
开发者ID:MerDane,项目名称:pyKinectTools,代码行数:33,代码来源:MSR_DailyActivities.py


示例9: read_wave

def read_wave(filename='sound.wav'):
    """Reads a wave file.

    filename: string

    returns: Wave
    """
    fp = open_wave(filename, 'r')

    nchannels = fp.getnchannels()
    nframes = fp.getnframes()
    sampwidth = fp.getsampwidth()
    framerate = fp.getframerate()
    
    z_str = fp.readframes(nframes)
    
    fp.close()

    dtype_map = {1:numpy.int8, 2:numpy.int16, 3:'special', 4:numpy.int32}
    if sampwidth not in dtype_map:
        raise ValueError('sampwidth %d unknown' % sampwidth)
    
    if sampwidth == 3:
        xs = numpy.fromstring(z_str, dtype=numpy.int8).astype(numpy.int32)
        ys = (xs[2::3] * 256 + xs[1::3]) * 256 + xs[0::3]
    else:
        ys = numpy.fromstring(z_str, dtype=dtype_map[sampwidth])

    # if it's in stereo, just pull out the first channel
    if nchannels == 2:
        ys = ys[::2]

    wave = Wave(ys, framerate)
    return wave
开发者ID:NSasquatch,项目名称:vocoder,代码行数:34,代码来源:thinkdsp.py


示例10: _read_data

def _read_data(record, start, end, info):
    """Read the binary data for each signal"""
    datfile = record + '.dat'
    samp_to_read = end - start

    # verify against first value in header
    with open(datfile, 'rb') as f:
        data = _arr_to_data(numpy.fromstring(f.read(3),
                        dtype=numpy.uint8).reshape(1,3))

    if [data[0, 2], data[0, 3]] != info['first_values']:
        warnings.warn(
            'First value from dat file does not match value in header')
    
    # read into an array with 3 bytes in each row
    with open(datfile, 'rb') as f:
        f.seek(start*3)
        arr = numpy.fromstring(f.read(3*samp_to_read),
                dtype=numpy.uint8).reshape((samp_to_read, 3))

    data = _arr_to_data(arr)

    # adjust zerovalue and gain
    data[:, 2] = (data[:, 2] - info['zero_values'][0]) / info['gains'][0]
    data[:, 3] = (data[:, 3] - info['zero_values'][1]) / info['gains'][1]

    # time columns
    data[:, 0] = numpy.arange(start, end)  # elapsed time in samples
    data[:, 1] = (numpy.arange(samp_to_read) + start
                  ) / info['samp_freq'] # in sec
    return data
开发者ID:DFNOsorio,项目名称:novainstrumentation,代码行数:31,代码来源:wfdbtools.py


示例11: read

    def read(self, fname, dim1, dim2, offset=0, bytecode="int32", endian="<"):
        """ 
        Read a binary image
        Parameters : fname, dim1, dim2, offset, bytecode, endian
        fname : file name : str
        dim1,dim2 : image dimensions : int
        offset : size of the : int 
        bytecode among : "int8","int16","int32","int64","uint8","uint16","uint32","uint64","float32","float64",...
        endian among short or long endian ("<" or ">")
        """
        self.filename = fname
        self.dim1 = dim1
        self.dim2 = dim2
        self.bytecode = bytecode
        f = open(self.filename, "rb")
        dims = [dim2, dim1]
        bpp = len(numpy.array(0, bytecode).tostring())
        size = dims[0] * dims[1] * bpp

        f.seek(offset)
        rawData = f.read(size)
        if  self.swap_needed(endian):
            data = numpy.fromstring(rawData, bytecode).byteswap().reshape(tuple(dims))
        else:
            data = numpy.fromstring(rawData, bytecode).reshape(tuple(dims))
        self.data = data
        return self
开发者ID:DawnScience,项目名称:dawn-fable,代码行数:27,代码来源:binaryimage.py


示例12: EMC_ReadData

def EMC_ReadData(filePath) :
    """ USAGE:
        reads a CSR sparse matrix from file and converts it
        to a Matrix library object in a CSR format
    
        PARAMETERS:
        filePath - full/relative path to the data file
    """
    
    # open file for reading
    inFile = open(filePath, "r")

    # read matrix shape
    matrixShape = numpy.fromstring(inFile.readline(), dtype = 'int', sep = ',');

    # read matrix data, indices and indptr
    data = numpy.fromstring(inFile.readline(), dtype = 'float', sep = ',');
    indices = numpy.fromstring(inFile.readline(), dtype = 'int', sep = ',');
    indptr = numpy.fromstring(inFile.readline(), dtype = 'int', sep = ',');

    # close file
    inFile.close()

    return sparse.csr_matrix((data, indices, indptr),
                             shape = (matrixShape[0], matrixShape[1]))
开发者ID:mrphilroth,项目名称:kaggle-emc,代码行数:25,代码来源:EMC_IO.py


示例13: _triage_write

def _triage_write(key, value, root, comp_kw):
    if isinstance(value, dict):
        sub_root = _create_titled_group(root, key, 'dict')
        for key, sub_value in value.items():
            if not isinstance(key, string_types):
                raise TypeError('All dict keys must be strings')
            _triage_write('key_{0}'.format(key), sub_value, sub_root, comp_kw)
    elif isinstance(value, (list, tuple)):
        title = 'list' if isinstance(value, list) else 'tuple'
        sub_root = _create_titled_group(root, key, title)
        for vi, sub_value in enumerate(value):
            _triage_write('idx_{0}'.format(vi), sub_value, sub_root, comp_kw)
    elif isinstance(value, type(None)):
        _create_titled_dataset(root, key, 'None', [False])
    elif isinstance(value, (int, float)):
        if isinstance(value, int):
            title = 'int'
        else:  # isinstance(value, float):
            title = 'float'
        _create_titled_dataset(root, key, title, np.atleast_1d(value))
    elif isinstance(value, string_types):
        if isinstance(value, text_type):  # unicode
            value = np.fromstring(value.encode('utf-8'), np.uint8)
            title = 'unicode'
        else:
            value = np.fromstring(value.encode('ASCII'), np.uint8)
            title = 'ascii'
        _create_titled_dataset(root, key, title, value, comp_kw)
    elif isinstance(value, np.ndarray):
        _create_titled_dataset(root, key, 'ndarray', value)
    else:
        raise TypeError('unsupported type %s' % type(value))
开发者ID:BushraR,项目名称:mne-python,代码行数:32,代码来源:_hdf5.py


示例14: ReadWav

def ReadWav(filename):
  wav = None
  try:
    wav = wave.open(filename, 'r')
    channels = wav.getnchannels()
    sample_bytes = wav.getsampwidth()

    wav_data = wav.readframes(wav.getnframes())

    if (sample_bytes == 2):
      wav_array = numpy.fromstring(wav_data, dtype=numpy.int16)
    elif (sample_bytes == 1):
      wav_array = numpy.fromstring(wav_data, dtype=numpy.int8)
    else:
      raise ValueError('Sample depth of %d bytes not supported' % sample_bytes)

    float_array = numpy.zeros(wav_array.shape[0] / channels)
    for i in range(channels):
      float_array += wav_array[i::channels]
    float_array /= max(abs(float_array))
  finally:
    if wav:
      wav.close()

  return float_array
开发者ID:luchak,项目名称:drum-factors,代码行数:25,代码来源:drum_factors.py


示例15: read_ermapper

    def read_ermapper(self, ifile):
        '''Read in a DEM file and associated .ers file'''
        ers_index = ifile.find('.ers')
        if ers_index > 0:
            data_file = ifile[0:ers_index]
            header_file = ifile
        else:
            data_file = ifile
            header_file = ifile + '.ers'

        self.header = self.read_ermapper_header(header_file)

        nroflines = int(self.header['nroflines'])
        nrofcellsperlines = int(self.header['nrofcellsperline'])
        self.data = self.read_ermapper_data(data_file, offset=int(self.header['headeroffset']))
        self.data = numpy.reshape(self.data,(nroflines,nrofcellsperlines))

        longy =  numpy.fromstring(self.getHeaderParam('longitude'), sep=':')
        latty =  numpy.fromstring(self.getHeaderParam('latitude'), sep=':')

        self.deltalatitude = float(self.header['ydimension'])
        self.deltalongitude = float(self.header['xdimension'])

        if longy[0] < 0:
            self.startlongitude = longy[0]+-((longy[1]/60)+(longy[2]/3600))
            self.endlongitude = self.startlongitude - int(self.header['nrofcellsperline'])*self.deltalongitude
        else:
            self.startlongitude = longy[0]+(longy[1]/60)+(longy[2]/3600)
            self.endlongitude = self.startlongitude + int(self.header['nrofcellsperline'])*self.deltalongitude
        if latty[0] < 0:
            self.startlatitude = latty[0]-((latty[1]/60)+(latty[2]/3600))
            self.endlatitude = self.startlatitude - int(self.header['nroflines'])*self.deltalatitude
        else:
            self.startlatitude = latty[0]+(latty[1]/60)+(latty[2]/3600)
            self.endlatitude = self.startlatitude + int(self.header['nroflines'])*self.deltalatitude
开发者ID:Dronecode,项目名称:MAVProxy,代码行数:35,代码来源:GAreader.py


示例16: pad

    def pad(self):
        """
        Pads the block to have k symbols of each symbolsize bytes.
        Each symbol will be interepreted as an array of unsigned integers
        """

        # loop through checking each symbol
        for i in xrange(len(self)):

            # Look for strings that are not numpy arrays
            if not isinstance(self[i], numpy.ndarray):

                # Figure out padding if any
                difference = self.symbolsize - len(self[i])
                self.padding += difference
                self[i] += b'\x00' * difference

                # Convert to numpy array
                self[i] = numpy.fromstring(self[i], dtype=self.dtype)

        # Add as many zero symbols as necessary to have a full block
        for i in xrange(len(self), self.k):
            src = b'\x00' * self.symbolsize
            self.padding += self.symbolsize
            array = numpy.fromstring(src, dtype=self.dtype)
            self.append(array)
开发者ID:absalon-james,项目名称:velopyraptor,代码行数:26,代码来源:block.py


示例17: alltoallv_string

def alltoallv_string(send_dict, comm=world):
    scounts = np.zeros(comm.size, dtype=np.int)
    sdispls = np.zeros(comm.size, dtype=np.int)
    stotal = 0
    for proc in range(comm.size):
        if proc in send_dict:
            data = np.fromstring(send_dict[proc],np.int8)
            scounts[proc] = data.size
            sdispls[proc] = stotal
            stotal += scounts[proc]

    rcounts = np.zeros(comm.size, dtype=np.int)
    comm.alltoallv( scounts, np.ones(comm.size, dtype=np.int), np.arange(comm.size, dtype=np.int),
                    rcounts, np.ones(comm.size, dtype=np.int), np.arange(comm.size, dtype=np.int) )
    rdispls = np.zeros(comm.size, dtype=np.int)
    rtotal = 0
    for proc in range(comm.size):
        rdispls[proc] = rtotal
        rtotal += rcounts[proc]
        rtotal += rcounts[proc]


    sbuffer = np.zeros(stotal, dtype=np.int8)
    for proc in range(comm.size):
        sbuffer[sdispls[proc]:(sdispls[proc]+scounts[proc])] = np.fromstring(send_dict[proc],np.int8)

    rbuffer = np.zeros(rtotal, dtype=np.int8)
    comm.alltoallv(sbuffer, scounts, sdispls, rbuffer, rcounts, rdispls)

    rdict = {}
    for proc in range(comm.size):
        rdict[proc] = rbuffer[rdispls[proc]:(rdispls[proc]+rcounts[proc])].tostring()

    return rdict
开发者ID:eojons,项目名称:gpaw-scme,代码行数:34,代码来源:__init__.py


示例18: faces_load_data

def faces_load_data():
 
    skip_rows = 1
    train_size = 28709
    test_size = 3589
    dim = 48
    X_train = np.empty([train_size,dim, dim])
    X_test = np.empty([test_size, dim, dim])
    y_train = np.empty(train_size)
    y_test = np.empty(test_size)
    
    f = open('fer2013/fer2013.csv', 'rb')
 
    train_index = test_index = 0
    for i, line in enumerate(f):
        if i >= skip_rows:
            split_line = line.split(",")
            usage = split_line[2].rstrip()
            if usage == 'Training':
                X_train[train_index, :,:] = np.fromstring(split_line[1], dtype = 'int', sep = ' ').reshape(dim, dim)
                y_train[train_index] = int(split_line[0])
                train_index += 1
            elif usage == 'PublicTest':
                X_test[test_index, :,:] = np.fromstring(split_line[1], dtype = 'int', sep = ' ').reshape(dim, dim)
                y_test[test_index] = int(split_line[0])
                test_index += 1
                 
    return (X_train, y_train) , (X_test, y_test)
开发者ID:IdoKenan,项目名称:faceExpress,代码行数:28,代码来源:load_data.py


示例19: _read_bucket

    def _read_bucket(self, doc, column_set, column_dtypes, include_symbol, include_images, columns):
        rtn = {}
        if doc[VERSION] != 3:
            raise ArcticException("Unhandled document version: %s" % doc[VERSION])
        rtn[INDEX] = np.cumsum(np.fromstring(lz4.decompress(doc[INDEX]), dtype='uint64'))
        doc_length = len(rtn[INDEX])
        rtn_length = len(rtn[INDEX])
        if include_symbol:
            rtn['SYMBOL'] = [doc[SYMBOL], ] * rtn_length
        column_set.update(doc[COLUMNS].keys())
        for c in column_set:
            try:
                coldata = doc[COLUMNS][c]
                dtype = np.dtype(coldata[DTYPE])
                values = np.fromstring(lz4.decompress(coldata[DATA]), dtype=dtype)
                self._set_or_promote_dtype(column_dtypes, c, dtype)
                rtn[c] = self._empty(rtn_length, dtype=column_dtypes[c])
                rowmask = np.unpackbits(np.fromstring(lz4.decompress(coldata[ROWMASK]),
                                                      dtype='uint8'))[:doc_length].astype('bool')
                rtn[c][rowmask] = values
            except KeyError:
                rtn[c] = None

        if include_images and doc.get(IMAGE_DOC, {}).get(IMAGE, {}):
            rtn = self._prepend_image(rtn, doc[IMAGE_DOC], rtn_length, column_dtypes, column_set, columns)
        return rtn
开发者ID:Laeeth,项目名称:arctic,代码行数:26,代码来源:tickstore.py


示例20: _read_symbology_block

    def _read_symbology_block(self, buf2):
        """ Read symbology block. """
        # Read and decode symbology header
        self.symbology_header = _unpack_from_buf(buf2, 0, SYMBOLOGY_HEADER)

        # Read radial packets
        packet_code = struct.unpack('>h', buf2[16:18])[0]
        assert packet_code in SUPPORTED_PACKET_CODES
        self.packet_header = _unpack_from_buf(buf2, 16, RADIAL_PACKET_HEADER)
        self.radial_headers = []
        nbins = self.packet_header['nbins']
        nradials = self.packet_header['nradials']
        nbytes = _unpack_from_buf(buf2, 30, RADIAL_HEADER)['nbytes']
        if packet_code == 16 and nbytes != nbins:
            nbins = nbytes  # sometimes these do not match, use nbytes
        self.raw_data = np.empty((nradials, nbins), dtype='uint8')
        pos = 30

        for radial in self.raw_data:
            radial_header = _unpack_from_buf(buf2, pos, RADIAL_HEADER)
            pos += 6
            if packet_code == 16:
                radial[:] = np.fromstring(buf2[pos:pos+nbins], '>u1')
                pos += radial_header['nbytes']
            else:
                assert packet_code == AF1F
                # decode run length encoding
                rle_size = radial_header['nbytes'] * 2
                rle = np.fromstring(buf2[pos:pos+rle_size], dtype='>u1')
                colors = np.bitwise_and(rle, 0b00001111)
                runs = np.bitwise_and(rle, 0b11110000) // 16
                radial[:] = np.repeat(colors, runs)
                pos += rle_size
            self.radial_headers.append(radial_header)
开发者ID:Rumpkie,项目名称:pyart,代码行数:34,代码来源:nexrad_level3.py



注:本文中的numpy.fromstring函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python numpy.full函数代码示例发布时间:2022-05-27
下一篇:
Python numpy.fromregex函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap