<legend id='jmOZ1'><style id='jmOZ1'><dir id='jmOZ1'><q id='jmOZ1'></q></dir></style></legend>
    1. <tfoot id='jmOZ1'></tfoot>

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

    2. <small id='jmOZ1'></small><noframes id='jmOZ1'>

        Numpy:如何在 numpy 中选择项目并为其赋值

        Numpy: how to select items in numpy and assign its value(Numpy:如何在 numpy 中选择项目并为其赋值)
          <legend id='09kHU'><style id='09kHU'><dir id='09kHU'><q id='09kHU'></q></dir></style></legend>

          <i id='09kHU'><tr id='09kHU'><dt id='09kHU'><q id='09kHU'><span id='09kHU'><b id='09kHU'><form id='09kHU'><ins id='09kHU'></ins><ul id='09kHU'></ul><sub id='09kHU'></sub></form><legend id='09kHU'></legend><bdo id='09kHU'><pre id='09kHU'><center id='09kHU'></center></pre></bdo></b><th id='09kHU'></th></span></q></dt></tr></i><div id='09kHU'><tfoot id='09kHU'></tfoot><dl id='09kHU'><fieldset id='09kHU'></fieldset></dl></div>
        1. <small id='09kHU'></small><noframes id='09kHU'>

                <tbody id='09kHU'></tbody>
                  <bdo id='09kHU'></bdo><ul id='09kHU'></ul>
                • <tfoot id='09kHU'></tfoot>
                  本文介绍了Numpy:如何在 numpy 中选择项目并为其赋值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在按列表分配新值时遇到问题.

                  I have got a problem in assigning new value by list.

                  我想通过 numpy 数组的索引更改 s numpy 中的 12 个项目值,我希望我选择的每个索引都是不同的.所以我制作了一个列表 random.sample(range(0,len(s),12) 来选择 12 个不同的索引.通过这个索引更改 numpy 数组 s() 中的一些值但是,我收到错误:SyntaxError: can't assign to function call

                  I want to change 12 items values in s numpy by numpy array's index ,and i hope every index i choose is different. so i made a list random.sample(range(0,len(s),12) to select 12 different index.And through this index change some of values in numpy array s() However, I'm getting the error: SyntaxError: can't assign to function call

                      import numpy as np
                      import random
                      N = 20
                      s = np.zeros([N])
                      alist = random.sample(range(0,20),12)
                      alist
                      for i in alist:
                         s(i)=10
                  

                  推荐答案

                  我不完全确定你想在这里实现什么,但 s(i) 是你的问题:圆括号暗示一个函数调用,但 s 是一个 numpy 数组,所以这不起作用.我认为您正在尝试为列表编制索引,在这种情况下您将使用 s[i].

                  I'm not totally sure what you're trying to achieve here, but s(i) is your problem: round brackets imply a function call, but s is a numpy array, so this won't work . I think you're trying to index the list, in which case you'd use s[i].

                  这篇关于Numpy:如何在 numpy 中选择项目并为其赋值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  What happens when you compare 2 pandas Series(当你比较 2 个 pandas 系列时会发生什么)
                  Quickly find differences between two large text files(快速查找两个大文本文件之间的差异)
                  Python - Compare 2 files and output differences(Python - 比较 2 个文件和输出差异)
                  Why do comparisions between very large float values fail in python?(为什么在 python 中非常大的浮点值之间的比较会失败?)
                  Dictionary merge by updating but not overwriting if value exists(字典通过更新合并,但如果值存在则不覆盖)
                  Find entries of one text file in another file in python(在python中的另一个文件中查找一个文本文件的条目)

                        <tbody id='BRaVu'></tbody>

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

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

                        <tfoot id='BRaVu'></tfoot>