• <tfoot id='hUckM'></tfoot>
    • <bdo id='hUckM'></bdo><ul id='hUckM'></ul>
    <i id='hUckM'><tr id='hUckM'><dt id='hUckM'><q id='hUckM'><span id='hUckM'><b id='hUckM'><form id='hUckM'><ins id='hUckM'></ins><ul id='hUckM'></ul><sub id='hUckM'></sub></form><legend id='hUckM'></legend><bdo id='hUckM'><pre id='hUckM'><center id='hUckM'></center></pre></bdo></b><th id='hUckM'></th></span></q></dt></tr></i><div id='hUckM'><tfoot id='hUckM'></tfoot><dl id='hUckM'><fieldset id='hUckM'></fieldset></dl></div>

    <legend id='hUckM'><style id='hUckM'><dir id='hUckM'><q id='hUckM'></q></dir></style></legend>

        <small id='hUckM'></small><noframes id='hUckM'>

        多次克隆 NumPy 数组

        Clone a NumPy array multiple times(多次克隆 NumPy 数组)
          <tbody id='Cmnx9'></tbody>
      1. <small id='Cmnx9'></small><noframes id='Cmnx9'>

        <legend id='Cmnx9'><style id='Cmnx9'><dir id='Cmnx9'><q id='Cmnx9'></q></dir></style></legend>

          <tfoot id='Cmnx9'></tfoot>
            <bdo id='Cmnx9'></bdo><ul id='Cmnx9'></ul>

                <i id='Cmnx9'><tr id='Cmnx9'><dt id='Cmnx9'><q id='Cmnx9'><span id='Cmnx9'><b id='Cmnx9'><form id='Cmnx9'><ins id='Cmnx9'></ins><ul id='Cmnx9'></ul><sub id='Cmnx9'></sub></form><legend id='Cmnx9'></legend><bdo id='Cmnx9'><pre id='Cmnx9'><center id='Cmnx9'></center></pre></bdo></b><th id='Cmnx9'></th></span></q></dt></tr></i><div id='Cmnx9'><tfoot id='Cmnx9'></tfoot><dl id='Cmnx9'><fieldset id='Cmnx9'></fieldset></dl></div>
                  本文介绍了多次克隆 NumPy 数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我将一张图片加载到一个 numpy 数组中,需要以 2 个不同的阈值对其图片进行阈值处理.

                  I loaded a picture into a numpy array and need to threshold it picture at 2 different thresholds.

                  import numpy as np
                  import cv2
                  
                  cap = cv2.Videocapture(0)
                  _,pic = cap.read()
                  pic1 = pic
                  pic2 = pic
                  
                  pic1[pic1 > 100] = 255
                  pic2[pic2 > 200] = 255
                  

                  当我只希望他们修改 pic1 和 pic2 时,此代码将始终编辑 pic

                  This code will always edit pic when I only want them to modify pic1 and pic2

                  推荐答案

                  在python中,对象和变量是有区别的.变量是分配给对象的名称;并且一个对象在内存中可以有多个名称.

                  In python, there is a difference between an object and a variable. A variable is name assigned to an object; and an object can have more than one name in memory.

                  通过 pic1 = pic;pic2 = pic,您将 same 对象分配给多个不同的变量名称,因此您最终会修改同一个对象.

                  By doing pic1 = pic; pic2 = pic, You're assigning the same object to multiple different variable names, so you end up modifying the same object.

                  你想要的是使用 np.ndarray.copy-

                  pic1 = pic.copy()
                  pic2 = pic.copy()
                  

                  或者,非常相似,使用 np.copy

                  Or, quite similarly, using np.copy

                  pic1, pic2 = map(np.copy, (pic, pic))
                  

                  这种语法实际上使 真的 很容易克隆 pic 任意多次:

                  This syntax actually makes it really easy to clone pic as many times as you like:

                  pic1, pic2, ... picN = map(np.copy, [pic] * N)
                  

                  其中 N 是您要创建的副本数.

                  Where N is the number of copies you want to create.

                  这篇关于多次克隆 NumPy 数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Initialize Multiple Numpy Arrays (Multiple Assignment) - Like MATLAB deal()(初始化多个 Numpy 数组(多重赋值) - 像 MATLAB deal())
                  How to extend Python class init(如何扩展 Python 类初始化)
                  What#39;s the difference between dict() and {}?(dict() 和 {} 有什么区别?)
                  What is a wrapper_descriptor, and why is Foo.__init__() one in this case?(什么是 wrapper_descriptor,为什么 Foo.__init__() 在这种情况下是其中之一?)
                  Initialize list with same bool value(使用相同的布尔值初始化列表)
                  setattr with kwargs, pythonic or not?(setattr 与 kwargs,pythonic 与否?)

                      <tbody id='6Prq4'></tbody>
                    <i id='6Prq4'><tr id='6Prq4'><dt id='6Prq4'><q id='6Prq4'><span id='6Prq4'><b id='6Prq4'><form id='6Prq4'><ins id='6Prq4'></ins><ul id='6Prq4'></ul><sub id='6Prq4'></sub></form><legend id='6Prq4'></legend><bdo id='6Prq4'><pre id='6Prq4'><center id='6Prq4'></center></pre></bdo></b><th id='6Prq4'></th></span></q></dt></tr></i><div id='6Prq4'><tfoot id='6Prq4'></tfoot><dl id='6Prq4'><fieldset id='6Prq4'></fieldset></dl></div>

                        • <bdo id='6Prq4'></bdo><ul id='6Prq4'></ul>

                          <small id='6Prq4'></small><noframes id='6Prq4'>

                        • <tfoot id='6Prq4'></tfoot>
                            <legend id='6Prq4'><style id='6Prq4'><dir id='6Prq4'><q id='6Prq4'></q></dir></style></legend>