我正在使用 fit_generator 函数来训练我的模型,并希望验证我的数据是否按预期构建和使用。我从 keras.utils.Sequence() 派生的类实现了方法__getitem__,__len__并且on_epoch_end看起来像这样:
class PairwiseSequence(Sequence):
"""Generator that returns a combination of simulations (over a
parametrizable amount of timesteps) and the corresponding metric distance.
pair_list: List of pairwise combinations of simulations
results: dictionary with results for the metric distance between
simulation pairs
sim_files: List of filenames representing single timesteps
batch_size: number of samples to process in a single interference run
"""
def __init__(self, pair_list, results, mean, std, train=False, sim_files=None,
batch_size=1):
self.pair_list = pair_list …Run Code Online (Sandbox Code Playgroud) 我和一位同事刚刚使用 f 字符串偶然发现了一个有趣的问题。这是一个最小的例子:
>>> f"{ 42:x}"
'2a'
Run Code Online (Sandbox Code Playgroud)
在十六进制类型后面写入空格会导致ValueError:
>>> f"{ 42:x }"
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Invalid format specifier
Run Code Online (Sandbox Code Playgroud)
我理解PEP 498 中忽略表达式中的前导和尾随空白段落意味着该空格实际上应该被忽略。
为什么空格字符会导致错误,其背后的原因是什么?
我正在分析极端天气事件。我的数据框名为 df ,如下所示:
| Date | Qm |
|------------|--------------|
| 1993-01-01 | 4881.977061 |
| 1993-02-01 | 4024.396839 |
| 1993-03-01 | 3833.664650 |
| 1993-04-01 | 4981.192526 |
| 1993-05-01 | 6286.879798 |
| 1993-06-01 | 6939.726070 |
| 1993-07-01 | 6492.936065 |
| ... | ... |
Run Code Online (Sandbox Code Playgroud)
我想知道极端事件是否与测量的异常值发生在同一年。因此,我使用 seaborn 做了我的箱线图:
# Qm boxplot analysis
boxplot = sns.boxplot(x=df.index.month,y=df['Qm'])
plt.show()
Run Code Online (Sandbox Code Playgroud)

现在,我想在同一个数字中显示与异常值相对应的年份。因此,用日期标记它们。
我已经检查了多个包含箱线图的库,但没有关于如何标记它们的线索。
PD:我在这个例子中使用了 seaborn,但任何可以提供帮助的库都将受到高度赞赏
谢谢!