小编Wiz*_*ard的帖子

用C++切片向量

[1:]在C++中有没有相当于Python 的列表切片与向量?我只想从矢量中获取除第一个元素之外的所有元素.

Python的列表切片运算符:

list1 = [1, 2, 3]
list2 = list1[1:]  

print(list2) # [2, 3]
Run Code Online (Sandbox Code Playgroud)

C++期望的结果:

std::vector<int> v1 = {1, 2, 3};
std::vector<int> v2;
v2 = v1[1:];

std::cout << v2 << std::endl;  //{2, 3}
Run Code Online (Sandbox Code Playgroud)

c++ vector

10
推荐指数
4
解决办法
9678
查看次数

使用OpenCV在图像上绘制十字

上下文:我正在执行对象本地化并希望实现抑制返回机制(即在动作之后红色边界框所在的图像上绘制黑色十字trigger.)

问题:我不知道如何准确地缩放与原始输入()相关的边界框(红色init_input).如果理解了这种缩放,则应将黑色十字准确地放置在红色边界框的中间.

我目前的此功能代码如下:

def IoR(b, init_input, prev_coord):
    """
    Inhibition-of-Return mechanism.

    Marks the region of the image covered by
    the bounding box with a black cross.

    :param b:
        The current bounding box represented as [x1, y1, x2, y2].

    :param init_input:
        The initial input volume of the current episode.

    :param prev_coord:
        The previous state's bounding box coordinates (x1, y1, x2, y2)
    """
    x1, y1, x2, y2 = prev_coord
    width = 12
    x_mid = …
Run Code Online (Sandbox Code Playgroud)

python opencv image-processing

5
推荐指数
1
解决办法
1783
查看次数

OpenCV 中的梯度方向

通过 Sobel 算子,我已经能够确定图像的梯度幅度。我在下面显示这个:

GradMag

现在我想确定梯度方向。为此,我关注了这篇文章,它使用了函数cv2.phase. 在此之后,角度被硬编码为特定颜色,具体取决于函数返回的度数。我的问题是这个函数为我返回的值在 0 到 90 度的范围内。因此,我得到的图像仅由红色和青色组成。

我的代码如下:

# where gray_blur is a grayscale image of dimension 512 by 512

# 3x3 sobel filters for edge detection
sobel_x = np.array([[ -1, 0, 1], 
                   [ -2, 0, 2], 
                   [ -1, 0, 1]])


sobel_y = np.array([[ -1, -2, -1], 
                   [ 0, 0, 0], 
                   [ 1, 2, 1]])


# Filter the blurred grayscale images using filter2D

filtered_blurred_x = cv2.filter2D(gray_blur, -1, sobel_x)  
filtered_blurred_y = cv2.filter2D(gray_blur, -1, sobel_y)

# …
Run Code Online (Sandbox Code Playgroud)

python opencv

5
推荐指数
2
解决办法
4003
查看次数

为神经网络打乱两个 numpy 数组

我有两个 numpy 数组用于输入数据 X 和输出数据 y。

X = np.array(([2, 3],                    # sample 1 x
              [16, 4]), dtype=float)     # sample 2 x
y = np.array(([1, 0],                    # sample 1 y
              [0, 1]), dtype=float)      # sample 2 y
Run Code Online (Sandbox Code Playgroud)

我想使用小批量来训练神经网络,如何在知道相应输出仍然对齐的情况下对两个数组进行洗牌?

python arrays numpy neural-network

4
推荐指数
1
解决办法
2378
查看次数

在 Python 中打印图形(顶点、边)

在 Python 中打印图形的最简单方法是什么?即我想可视化图形的最大集团。

我目前的数据结构是:

adjacency_matrix = [[False, True, False, ...], 
                    [True, False, True, ...],
                    ..]

adjacency_set = [[45, 2], [1, 32], ...]

max_clique = [23, 143, 1, 2, 42, 12, 3, ...] # the vertices in the max clique
Run Code Online (Sandbox Code Playgroud)

我会使用 matplotlib 来做到这一点吗?

python graph-theory matplotlib

1
推荐指数
1
解决办法
1万
查看次数

创建特定的排列Python

我有二维列表的值:

# 4 x 4, 2-dimensional list
values = [[4, 7, 8], 
          [1, 3, 4], 
          [7, 5, 6], 
          [2, 9, 1]]
Run Code Online (Sandbox Code Playgroud)

我想为每个列表创建包含这些值的所有可能排列(笛卡尔积)的元组.

# example for the list at index 0 of values
args0 = [(4, 7, 8), (7, 4, 8), (4, 8, 7), (8, 4, 7), (7, 8, 4), (8, 7, 4)] 
Run Code Online (Sandbox Code Playgroud)

有一个简单的方法来解决这个问题吗?我已经尝试过itertools,但无法使用"特定值".

python list permutation python-itertools

0
推荐指数
1
解决办法
29
查看次数

按字典顺序对字符串排序

我想按字典顺序打印这些单词。我以为这样sorted()排列单词。我也尝试过.sort()返回相同的顺序。还是我缺少按词典顺序排序的东西?

码:

a_list = ['Zrhregegrydb', 'cygzRFWDWBdvF']
for word in sorted(a_list):
    print(word)
Run Code Online (Sandbox Code Playgroud)

输出:

# Zrhregegrydb
# cygzRFWDWBdvF
Run Code Online (Sandbox Code Playgroud)

所需输出:

# cygzRFWDWBdvF
# Zrhregegrydb
Run Code Online (Sandbox Code Playgroud)

python sorting list lexicographic

0
推荐指数
2
解决办法
7379
查看次数

大多数pythonic方式确定最低计数

我发现自己想要在迭代字典时保持最低/最大计数.

例如:

d = {
    'Bob': 2000,
    'Larry': 6000,
    'Mary': 5
}

lowest_value = 1000000
list_of_keys = []

for key, value in d.items():
    if value > 100:
        list_of_keys.append(key)
        if value < lowest_value:
            lowest_value = value
Run Code Online (Sandbox Code Playgroud)

而不是将我设置lowest_value为肯定比第一个更大的数字,if value < lowest_value:有没有更好的方法来做到这一点?

因为largest_count我通常只能使用0或-1.

python iteration

0
推荐指数
1
解决办法
70
查看次数

使用makefile编译错误

我在c中编写了一个程序,我在windows上的cygwin中使用make文件来编译文件.在Visual Studio中执行完全正常,但是当我尝试使用我的make文件时,会发生以下情况:

错误:

$ make
gcc    -c -o mathTable.o mathTable.c
mathTable.c:1:1: error: stray ‘\377’ in program
 ??# i n c l u d e   < s t d l i b . h >
 ^
mathTable.c:1:2: error: stray ‘\376’ in program
 ??# i n c l u d e   < s t d l i b . h >
  ^
mathTable.c:1:3: error: stray ‘#’ in program
 ??# i n c l u d e   < s t d l i …
Run Code Online (Sandbox Code Playgroud)

makefile

-1
推荐指数
2
解决办法
360
查看次数