• <bdo id='KbWdu'></bdo><ul id='KbWdu'></ul>
  • <small id='KbWdu'></small><noframes id='KbWdu'>

      <tfoot id='KbWdu'></tfoot>
        <legend id='KbWdu'><style id='KbWdu'><dir id='KbWdu'><q id='KbWdu'></q></dir></style></legend>

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

      1. Python逐元素元组操作,如sum

        Python element-wise tuple operations like sum(Python逐元素元组操作,如sum)

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

        • <small id='o1mFa'></small><noframes id='o1mFa'>

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

                  <legend id='o1mFa'><style id='o1mFa'><dir id='o1mFa'><q id='o1mFa'></q></dir></style></legend>
                    <tbody id='o1mFa'></tbody>
                1. 本文介绍了Python逐元素元组操作,如sum的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  有没有办法让 Python 中的元组操作像这样工作:

                  Is there anyway to get tuple operations in Python to work like this:

                  >>> a = (1,2,3)
                  >>> b = (3,2,1)
                  >>> a + b
                  (4,4,4)
                  

                  代替:

                  >>> a = (1,2,3)
                  >>> b = (3,2,1)
                  >>> a + b
                  (1,2,3,3,2,1)
                  

                  我知道它是这样工作的,因为 __add____mul__ 方法被定义为这样工作.那么唯一的方法就是重新定义它们?

                  I know it works like that because the __add__ and __mul__ methods are defined to work like that. So the only way would be to redefine them?

                  推荐答案

                  import operator
                  tuple(map(operator.add, a, b))
                  

                  这篇关于Python逐元素元组操作,如sum的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 与否?)

                  • <bdo id='ATZw2'></bdo><ul id='ATZw2'></ul>

                            <tbody id='ATZw2'></tbody>

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

                        1. <tfoot id='ATZw2'></tfoot>

                            <i id='ATZw2'><tr id='ATZw2'><dt id='ATZw2'><q id='ATZw2'><span id='ATZw2'><b id='ATZw2'><form id='ATZw2'><ins id='ATZw2'></ins><ul id='ATZw2'></ul><sub id='ATZw2'></sub></form><legend id='ATZw2'></legend><bdo id='ATZw2'><pre id='ATZw2'><center id='ATZw2'></center></pre></bdo></b><th id='ATZw2'></th></span></q></dt></tr></i><div id='ATZw2'><tfoot id='ATZw2'></tfoot><dl id='ATZw2'><fieldset id='ATZw2'></fieldset></dl></div>
                          1. <legend id='ATZw2'><style id='ATZw2'><dir id='ATZw2'><q id='ATZw2'></q></dir></style></legend>