我正在使用谷歌colab为我的项目.我在图像上得到网格线,即使我没有写它们.
from matplotlib import pyplot as plt
%matplotlib inline
import cv2
img = cv2.imread('k15.jpg')
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
plt.imshow(img)
Run Code Online (Sandbox Code Playgroud)
对于像上面这样的代码,我得到网格线,当我在python shell中运行相同的代码时,情况并非如此.
我从未在 jupyter notebook 中使用过 bash。对于某些项目,我需要将 bash 与 python 一起使用,但它给了我错误。我也安装了 bash 内核。
PATH="/Downloads/dogscats/"
!ls {PATH}
Run Code Online (Sandbox Code Playgroud)
'ls' 不是内部或外部命令,也不是可运行的程序或批处理文件。
我需要像这样转换数组:
[[1527 1369 86 86]
[ 573 590 709 709]
[1417 1000 68 68]
[1361 1194 86 86]]
Run Code Online (Sandbox Code Playgroud)
喜欢这个:
[(726, 1219, 1281, 664),
(1208, 1440, 1283, 1365),
(1006, 1483, 1069, 1421),
(999, 1414, 1062, 1351),]
Run Code Online (Sandbox Code Playgroud)
我尝试直接使用 convert to tuple 但得到了这个:
( array([1527, 1369, 86, 86], dtype=int32),
array([573, 590, 709, 709], dtype=int32),
array([1417, 1000, 68, 68], dtype=int32),
array([1361, 1194, 86, 86], dtype=int32))
(array([701, 899, 671, 671], dtype=int32),)
Run Code Online (Sandbox Code Playgroud) 给定一个numpy数组,如何在其中找到索引序列,以便对结果进行排序?
例如,给定x=[4,2,6],结果将是[1,0,2],因为[x[1],x[0],x[2]]是排序的.
我知道有很多可用的Python函数argsort()可以完成这项工作,但我需要自己实现这个排序功能.有什么建议?