Here are the examples of the python api numpy.frombuffer taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
145 Examples
3
View Complete Implementation : strategy_gen_4.py
Copyright GNU Lesser General Public License v3.0
Author : Kismuz
Copyright GNU Lesser General Public License v3.0
Author : Kismuz
def get_external_state(self):
x_sma = np.stack(
[
np.frombuffer(self.data.sma_16.get(size=self.time_dim)),
np.frombuffer(self.data.sma_32.get(size=self.time_dim)),
np.frombuffer(self.data.sma_64.get(size=self.time_dim)),
np.frombuffer(self.data.sma_128.get(size=self.time_dim)),
np.frombuffer(self.data.sma_256.get(size=self.time_dim)),
],
axis=-1
)
# Gradient along features axis:
diff = np.gradient(x_sma, axis=-1) * self.p.state_ext_scale
diff = tanh(diff)
avg = np.gradient(x_sma, axis=0) * self.p.state_ext_scale
avg = tanh(avg)
return {'avg': avg[:, None, :], 'diff': diff[:, None, :]}
3
View Complete Implementation : strategy_gen_4.py
Copyright GNU Lesser General Public License v3.0
Author : Kismuz
Copyright GNU Lesser General Public License v3.0
Author : Kismuz
def get_external_state(self):
x = np.stack(
[
np.frombuffer(self.channel_O.get(size=self.time_dim)),
np.frombuffer(self.channel_H.get(size=self.time_dim)),
np.frombuffer(self.channel_L.get(size=self.time_dim)),
],
axis=-1
)
# Amplify and squash in [-1,1], seems to be best option as of 4.10.17:
# `self.p.state_ext_scale` param is supposed to keep most of the signal
# in 'linear' part of tanh while squashing spikes.
x_market = tanh(x * self.p.state_ext_scale)
return x_market[:, None, :]
3
View Complete Implementation : strategy_gen_4.py
Copyright GNU Lesser General Public License v3.0
Author : Kismuz
Copyright GNU Lesser General Public License v3.0
Author : Kismuz
def get_external_state(self):
x_sma = np.stack(
[
np.frombuffer(self.data.sma_16.get(size=self.time_dim)),
np.frombuffer(self.data.sma_32.get(size=self.time_dim)),
np.frombuffer(self.data.sma_64.get(size=self.time_dim)),
np.frombuffer(self.data.sma_128.get(size=self.time_dim)),
np.frombuffer(self.data.sma_256.get(size=self.time_dim)),
],
axis=-1
)
# Gradient along features axis:
dx = np.gradient(x_sma, axis=-1) * self.p.state_ext_scale
x = tanh(dx)
return x[:, None, :]
3
View Complete Implementation : test_rtrl_base_env.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : kindredresearch
Copyright BSD 3-Clause "New" or "Revised" License
Author : kindredresearch
def _compute_actuation_(self, action, timestamp, index):
if self.crash_flag.value == 2:
raise Exception("Compute actuation crash triggered.")
self._actuation_packet_['generic1'] = action
self._actuation_packet_['generic2'] = action
values = self._rand_obj_.uniform(-1, +1, 3)
rand_state_array_type, rand_state_array_size, rand_state_array = utils.get_random_state_array(
self._rand_obj_.get_state()
)
np.copyto(self._shared_rstate_array_, np.frombuffer(rand_state_array, dtype=rand_state_array_type))
np.copyto(self._uniform_array_, values)
3
View Complete Implementation : WSR98DFile.py
Copyright MIT License
Author : YvZheng
Copyright MIT License
Author : YvZheng
def _parse_BaseDataHeader(self):
BaseDataHeader = {}
fixed_buf = self.fid.read(dtype_98D.CutConfigurationBlockPos) ##读取前面固定头的信息
BaseDataHeader['GenericHeader'], _ = _unpack_from_buf(fixed_buf, \
dtype_98D.GenericHeaderBlockPos,
dtype_98D.BaseDataHeader['GenericHeaderBlock'])
BaseDataHeader['SiteConfig'], _ = _unpack_from_buf(fixed_buf, \
dtype_98D.SiteConfigurationBlockPos,
dtype_98D.BaseDataHeader['SiteConfigurationBlock'])
BaseDataHeader['TaskConfig'], _ = _unpack_from_buf(fixed_buf,
dtype_98D.TaskConfigurationBlockPos,
dtype_98D.BaseDataHeader['TaskConfigurationBlock'])
cut_buf = self.fid.read(dtype_98D.CutConfigurationBlockSize * \
BaseDataHeader['TaskConfig']['CutNumber'])
BaseDataHeader['CutConfig'] = np.frombuffer(cut_buf, dtype_98D.BaseDataHeader['CutConfigurationBlock'])
return BaseDataHeader
3
View Complete Implementation : netcdf.py
Copyright MIT License
Author : jgagneastro
Copyright MIT License
Author : jgagneastro
def _read(self):
# Check magic bytes and version
magic = self.fp.read(3)
if not magic == b'CDF':
raise TypeError("Error: %s is not a valid NetCDF 3 file" %
self.filename)
self.__dict__['version_byte'] = frombuffer(self.fp.read(1), '>b')[0]
# Read file headers and set data.
self._read_numrecs()
self._read_dim_array()
self._read_gatt_array()
self._read_var_array()
3
View Complete Implementation : WSR98DFile.py
Copyright MIT License
Author : YvZheng
Copyright MIT License
Author : YvZheng
def _parse_radial_single(self):
radial_var = {}
for _ in range(self.MomentNum):
Mom_buf = self.fid.read(dtype_98D.MomentHeaderBlockSize)
Momheader, _ = _unpack_from_buf(Mom_buf, 0, dtype_98D.RadialData())
Data_buf = self.fid.read(Momheader['Length'])
astert (Momheader['BinLength'] == 1) | (Momheader['BinLength'] == 2), "Bin Length has problem!"
if Momheader['BinLength'] == 1:
dat_tmp = (np.frombuffer(Data_buf, dtype="u1", offset=0)).astype(int)
else:
dat_tmp = (np.frombuffer(Data_buf, dtype="u2", offset=0)).astype(int)
radial_var[dtype_98D.flag2Product[Momheader['DataType']]] = np.where(dat_tmp >= 5, \
(dat_tmp - Momheader['Offset']) /
Momheader['Scale'],
np.nan).astype(np.float32)
return radial_var
3
View Complete Implementation : netcdf.py
Copyright MIT License
Author : alvarob96
Copyright MIT License
Author : alvarob96
def _read(self):
# Check magic bytes and version
magic = self.fp.read(3)
if not magic == b'CDF':
raise TypeError("Error: %s is not a valid NetCDF 3 file" %
self.filename)
self.__dict__['version_byte'] = frombuffer(self.fp.read(1), '>b')[0]
# Read file headers and set data.
self._read_numrecs()
self._read_dim_array()
self._read_gatt_array()
self._read_var_array()
3
View Complete Implementation : CCFile.py
Copyright MIT License
Author : YvZheng
Copyright MIT License
Author : YvZheng
def _parse_radial_single(self, buf_radial, radialnumber):
"""解析径向的数据"""
Radial = {}
RadialData = np.frombuffer(buf_radial, dtype_cc.RadialData(radialnumber))
Radial['fields'] = {}
Radial['fields']['dBZ'] = np.where(RadialData['dBZ'] != -32768, RadialData['dBZ'] / 10.,
np.nan).astype(np.float32)
Radial['fields']['V'] = np.where(RadialData['V'] != -32768, RadialData['V'] / 10.,
np.nan).astype(np.float32)
Radial['fields']['W'] = np.where(RadialData['W'] != -32768, RadialData['W'] / 10.,
np.nan).astype(np.float32)
return Radial
3
View Complete Implementation : level3.py
Copyright GNU General Public License v3.0
Author : CyanideCN
Copyright GNU General Public License v3.0
Author : CyanideCN
def _rhi(self):
azi = np.frombuffer(self.buf.read(4), "f4")[0]
top = np.frombuffer(self.buf.read(4), "f4")[0]
bot = np.frombuffer(self.buf.read(4), "f4")[0]
self.params["azimuth"] = azi
self.params["top"] = top
self.params["bottom"] = bot