我正在尝试在图像顶部可视化边界框。
我的代码:
color = (255, 255, 0)
thickness = 4
x_min, y_min, x_max, y_max = bbox
cv2.rectangle(img, (x_min, y_min), (x_max, y_max), color, thickness=thickness)
Run Code Online (Sandbox Code Playgroud)
我得到
TypeError: Argument given by name ('thickness') and position (4)
即使我通过厚度位置上,我得到一个不同的回溯:
cv2.rectangle(img, (x_min, y_min), (x_max, y_max), color, thickness)
Run Code Online (Sandbox Code Playgroud)
加注 TypeError: expected a tuple.
我试图df.set_index以这样的方式调用,即dtype我 set_index 的列是 new index.dtype。不幸的是,在下面的示例中,set_index 更改了dtype.
df = pd.DataFrame({'a': pd.Series(np.array([-1, 0, 1, 2], dtype=np.int8))})
df['ignore'] = df['a']
assert (df.dtypes == np.int8).all() # fine
df2= df.set_index('a')
assert df2.index.dtype == df['a'].dtype, df2.index.dtype
Run Code Online (Sandbox Code Playgroud)
是否可以避免这种行为?我的pandas版本是0.23.3
相似地,
new_idx = pd.Index(np.array([-1, 0, 1, 2]), dtype=np.dtype('int8'))
assert new_idx.dtype == np.dtype('int64')
Run Code Online (Sandbox Code Playgroud)
尽管 dtype 参数的文档说:“如果提供了实际的 dtype,如果它是安全的,我们会强制使用该 dtype。否则,将会引发错误。”
通常,我在笔记本中途发现自己忘记了导入,而是想将其移动到笔记本的顶部(我试图保留大部分导入)。有没有一种方法可以将键盘快捷方式添加到~/.jupyter/custom/custom.js将单元格移动到笔记本顶部的方式?
目前,我是通过剪切单元格,滚动到笔记本顶部,粘贴并向下滚动到我原来的位置(通常在返回的途中丢失位置)来完成此操作的。
以下是来自fastai论坛的一些代码,它们可以完成不同的任务:转到运行单元:
Jupyter.keyboard_manager.command_shortcuts.add_shortcut('CMD-I', {
help : 'Go to Running cell',
help_index : 'zz',
handler : function (event) {
setTimeout(function() {
// Find running cell and click the first one
if ($('.running').length > 0) {
//alert("found running cell");
$('.running')[0].scrollIntoView();
}}, 250);
return false;
}
});
Run Code Online (Sandbox Code Playgroud)
We have a scheduled github action that fails sometimes. How can I receive email notifications if it fails. At the moment, only the creator of the workflow receives email notifications when it fails.
我想格式化A1:E14为美元、F1:K14百分比和A15:Z1000美元。有没有办法在 XlsxWriter 中做到这一点?
我知道如何将完整列格式化为 Dollars/Percentages,但我不知道如何格式化列的一部分——无论我最后做什么都会覆盖 Columns F:K。
数据从大熊猫开始,很高兴在那里解决问题。以下似乎不起作用:
sheet.set_column('A1:E14', None, money_format)
Run Code Online (Sandbox Code Playgroud)
更多代码:
with pd.ExcelWriter(write_path) as writer:
book = writer.book
money_fmt = book.add_format({'num_format': '$#,##0'})
pct_fmt = book.add_format({'num_format': '0.00%'})
# call func that creates a worksheet named total with no format
df.to_excel(writer, sheet_name='Total', startrow=0)
other_df.to_excel(writer, sheet_name='Total', startrow=15)
writer.sheets['Total'].set_column('A1:E14',20, money_fmt)
writer.sheets['Total'].set_column('F1:K14',20, pct_fmt)
writer.sheets['Total'].set_column('F15:Z1000', 20, money_fmt)
Run Code Online (Sandbox Code Playgroud) 我已经设置了一个计算实例,用于使用具有以下角色的服务帐户在 Google Compute 引擎上运行 cronjobs:
Custom Compute Image User + Deletion rights
Compute Admin
Compute Instance Admin (beta)
Kubernetes Engine Developer
Logs Writer
Logs Viewer
Pub/Sub Editor
Source Repository Reader
Storage Admin
不幸的是,当我 ssh 进入这个 cronjob runner 实例然后运行时:
sudo gcloud compute --project {REDACTED} instances create e-latest \
--zone {REDACTED} --machine-type n1-highmem-8 --subnet default \
--maintenance-policy TERMINATE \
--scopes https://www.googleapis.com/auth/cloud-platform \
--boot-disk-size 200 \
--boot-disk-type pd-standard --boot-disk-device-name e-latest \
--image {REDACTED} --image-project {REDACTED} \
--service-account NAME_OF_SERVICE_ACCOUNT \
--accelerator type=nvidia-tesla-p100,count=1 --min-cpu-platform Automatic …Run Code Online (Sandbox Code Playgroud) 我试图用以下方法使DeprecationWarning保持沉默.
import warnings
warnings.filterwarnings(action='ignore')
from sklearn.ensemble import RandomForestRegressor
Run Code Online (Sandbox Code Playgroud)
但是,它仍然显示:
DeprecationWarning:numpy.core.umath_tests是一个内部NumPy模块,不应导入.它将在未来的NumPy版本中删除.来自numpy.core.umath_tests导入inner1d
为什么会发生这种情况,我该如何解决?
我在python 3.6.6,numpy 1.15.0和scikit-learn 0.19.2上运行它,并且添加category=DeprecationWarning没有帮助.
为什么这个数据集会尝试遍历最后一个元素
from torch.utils.data.dataset import Dataset
class DumbDataset(Dataset):
def __init__(self, dct):
self.dct = dct
self.mapping = dict(enumerate(dct))
def __getitem__(self, index):
return self.dct[self.mapping[index]]
def __len__(self):
print('called')
return len(self.dct)
ds = DumbDataset({'a': 'aword', 'b': 'another_words'})
for k in ds: print(k)
Run Code Online (Sandbox Code Playgroud)
这引发了 KeyError: 2,我不明白,因为对象的长度是 2。迭代器用完后不应该得到 StopIteration 吗?
我正在创建一个将大型 numpy 数组存储在pyarrow.plasma. 我想给每个数组一个唯一的、确定性的 plasma.ObjectID,np.array遗憾的是不可散列我当前的(损坏的)方法是:
import numpy as np
from pyarrow import plasma
def int_to_bytes(x: int) -> bytes:
return x.to_bytes(
(x.bit_length() + 7) // 8, "big"
) # /sf/ask/1471238891/
def get_object_id(arr):
arr_id = int(arr.sum() / (arr.shape[0]))
oid: bytes = int_to_bytes(arr_id).zfill(20) # fill from left with zeroes, must be of length 20
return plasma.ObjectID(oid)
Run Code Online (Sandbox Code Playgroud)
但这很容易失败,例如:
arr = np.arange(12)
a1 = arr.reshape(3, 4)
a2 = arr.reshape(3,2,2)
assert get_object_id(a1) != get_object_id(a2), 'Hash collision'
# another good test case …Run Code Online (Sandbox Code Playgroud) 我有一个连接到的谷歌云计算实例
INSTANCE_NAME='sam_vm'
gcloud beta compute ssh --zone "us-central1-a" $INSTANCE_NAME --project sam_project
Run Code Online (Sandbox Code Playgroud)
当我尝试使用 cmd-p 连接然后输入该命令时,我得到:
ssh: Could not resolve hostname gcloud beta compute ssh --zone "us-central1-a" "shleifer-v1-vm" --project $hf_proj: nodename nor servname provided, or not known
Run Code Online (Sandbox Code Playgroud)
我怎样才能连接?
python ×6
pandas ×2
github ×1
google-iam ×1
hash ×1
javascript ×1
jupyter ×1
numpy ×1
opencv ×1
openpyxl ×1
pyarrow ×1
pytorch ×1
scikit-learn ×1
vision ×1
xlsxwriter ×1