def lab2npy(input_path, out, frame_rate= 0.01):
"""
frame_rate : sampling rate, typically 10 ms (or 0.01s)
"""
name=os.path.basename(input_path)
df=pd.read_table(input_path, sep=" ", header=None)
df.columns=["onset", "offset", "phone", "score"]
#onset and offset are in 100* nanosecond. Need to be put in second
df["onset"]=df["onset"]*10**(-7)
df["offset"]=df["offset"]*10**(-7)
phones=['a{}'.format(i) for i in range(1, 49)]
list_feats=[]
R=np.empty(1)
R[0]=frame_rate
for i in range(len(df)):
on=df["onset"].iloc[i]
off=df["offset"].iloc[i]
nb_frame=int(np.floor_divide((off-on),R[0]))
for ff in range(nb_frame):
one_hot=np.empty(len(phones))
for j in range(len(phones)):
if df["phone"][i]==phones[j]:
one_hot[j]=1
else:
one_hot[j]=0
list_feats.append(one_hot)
arr_feats = np.array(list_feats)
directory=out + "/npy/"
try:
os.stat(directory)
except:
os.mkdir(directory)
np.save(directory + "/"+ name.split(".")[0], arr=arr_feats, allow_pickle=False)
python类floor_divide()的实例源码
def test_floor_division_complex(self):
# check that implementation is correct
msg = "Complex floor division implementation check"
x = np.array([.9 + 1j, -.1 + 1j, .9 + .5*1j, .9 + 2.*1j], dtype=np.complex128)
y = np.array([0., -1., 0., 0.], dtype=np.complex128)
assert_equal(np.floor_divide(x**2, x), y, err_msg=msg)
# check overflow, underflow
msg = "Complex floor division overflow/underflow check"
x = np.array([1.e+110, 1.e-110], dtype=np.complex128)
y = np.floor_divide(x**2, x)
assert_equal(y, [1.e+110, 0], err_msg=msg)
def __floordiv__(self, other):
"""
Divide other into self, and return a new masked array.
"""
if self._delegate_binop(other):
return NotImplemented
return floor_divide(self, other)
def __rfloordiv__(self, other):
"""
Divide self into other, and return a new masked array.
"""
return floor_divide(other, self)
def int_div(x1: Number = 1.0, x2: Number = 2.0) -> Int:
return np.floor_divide(x1, x2)
def __floordiv__(self, other):
return floor_divide(self, other)
def __ifloordiv__(self, other):
return floor_divide(self, other, self)
def __rfloordiv__(self, other):
return floor_divide(other, self)
def generate_op(self, op, out, x, y):
self.append("np.floor_divide({}, {}, out={})", x, y, out)
def vox_to_pos(self, vox):
return np.floor_divide(vox - self.MOVE_GRID_OFFSET, self.MOVE_DELTA).astype(np.int64)
def get_output_margin(model_config):
return np.floor_divide(model_config.input_fov_shape - model_config.output_fov_shape, 2)
def __init__(self, volume, shape, label_margin=None):
self.volume = volume
self.shape = shape
self.margin = np.floor_divide(self.shape, 2).astype(np.int64)
if label_margin is None:
label_margin = np.zeros(3, dtype=np.int64)
self.label_margin = label_margin
self.skip_blank_sections = True
self.ctr_min = self.margin
self.ctr_max = (np.array(self.volume.shape) - self.margin - 1).astype(np.int64)
self.random = np.random.RandomState(CONFIG.random_seed)
# If the volume has a mask channel, further limit ctr_min and
# ctr_max to lie inside a margin in the AABB of the mask.
if self.volume.mask_data is not None:
mask_min, mask_max = self.volume.mask_bounds
mask_min = self.volume.local_coord_to_world(mask_min)
mask_max = self.volume.local_coord_to_world(mask_max)
self.ctr_min = np.maximum(self.ctr_min, mask_min + self.label_margin)
self.ctr_max = np.minimum(self.ctr_max, mask_max - self.label_margin - 1)
if np.any(self.ctr_min >= self.ctr_max):
raise ValueError('Cannot generate subvolume bounds: bounds ({}, {}) too small for shape ({})'.format(
np.array_str(self.ctr_min), np.array_str(self.ctr_max), np.array_str(self.shape)))
def __init__(self, parent, partitioning, partition_index):
super(PartitionedVolume, self).__init__(
parent,
parent.resolution,
image_data=parent.image_data,
label_data=parent.label_data,
mask_data=parent.mask_data)
self.partitioning = np.asarray(partitioning)
self.partition_index = np.asarray(partition_index)
partition_shape = np.floor_divide(np.array(self.parent.shape), self.partitioning)
self.bounds = ((np.multiply(partition_shape, self.partition_index)).astype(np.int64),
(np.multiply(partition_shape, self.partition_index + 1)).astype(np.int64))
def shape(self):
return tuple(np.floor_divide(np.array(self.parent.shape), self.scale))
def test_floor_division_complex(self):
# check that implementation is correct
msg = "Complex floor division implementation check"
x = np.array([.9 + 1j, -.1 + 1j, .9 + .5*1j, .9 + 2.*1j], dtype=np.complex128)
y = np.array([0., -1., 0., 0.], dtype=np.complex128)
assert_equal(np.floor_divide(x**2, x), y, err_msg=msg)
# check overflow, underflow
msg = "Complex floor division overflow/underflow check"
x = np.array([1.e+110, 1.e-110], dtype=np.complex128)
y = np.floor_divide(x**2, x)
assert_equal(y, [1.e+110, 0], err_msg=msg)
def __floordiv__(self, other):
"""
Divide other into self, and return a new masked array.
"""
if self._delegate_binop(other):
return NotImplemented
return floor_divide(self, other)
def __rfloordiv__(self, other):
"""
Divide self into other, and return a new masked array.
"""
return floor_divide(other, self)
def __ifloordiv__(self, other):
""" See __div__. """
oth = sanitize_units_mul(self, other)
np.floor_divide(self, oth, out=self)
return self
def plot_minute_histogram(splits):
def plot(ax, detections):
bins = np.floor_divide(detections['timestamp'], 60).astype('int64')
counts = np.bincount(bins)
ax.plot(counts)
ax.set_xlabel('Minute')
ax.set_ylabel('Count')
fig = plt.figure()
plot_rxtx_matrix(fig, splits, plot)
fig.suptitle('Histogram of number of detections per minute')
test_umath.py 文件源码
项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda
作者: SignalMedia
项目源码
文件源码
阅读 39
收藏 0
点赞 0
评论 0
def test_floor_division_complex(self):
# check that implementation is correct
msg = "Complex floor division implementation check"
x = np.array([.9 + 1j, -.1 + 1j, .9 + .5*1j, .9 + 2.*1j], dtype=np.complex128)
y = np.array([0., -1., 0., 0.], dtype=np.complex128)
assert_equal(np.floor_divide(x**2, x), y, err_msg=msg)
# check overflow, underflow
msg = "Complex floor division overflow/underflow check"
x = np.array([1.e+110, 1.e-110], dtype=np.complex128)
y = np.floor_divide(x**2, x)
assert_equal(y, [1.e+110, 0], err_msg=msg)