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

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

      1. “TypeError: 'function' 对象不支持项目分配"

        时间:2023-10-19

        • <tfoot id='havhJ'></tfoot>

                <tbody id='havhJ'></tbody>

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

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

                • <legend id='havhJ'><style id='havhJ'><dir id='havhJ'><q id='havhJ'></q></dir></style></legend>

                • 本文介绍了“TypeError: 'function' 对象不支持项目分配"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有两个矩阵

                  fi = [[f1],           Nij = [[N11 N12 .......N1n],
                        [f2],                  [N21 N22 .......N2n],
                         .                            ...
                         .                            ...
                        [fn]]                  [Nn1 Nn2 .......Nnn]]
                  

                  我想乘:

                  f1 to each element of the 1st row,
                  f2 to each element of the 2nd row,
                  

                  等等.

                  即我想要 Xij = fi*Nij 其中 fi 是列矩阵,Xij &Nij 是 nxn 矩阵.

                  I.e. I want Xij = fi*Nij where fi is a column matrix and Xij & Nij is nxn matrix.

                  我尝试过使用

                  import numpy as np
                  
                  fi = np.linspace(1,5, num =5)
                  fi = np.asmatrix(fi)
                  
                  def Xij(ai):
                      Nij = np.ones((5,5))
                      for i in range(len(fi)):
                      for j in range(len(fi)):
                          Xij[i,j] = ai[i] * Nij[i,j]
                  return Xij
                  
                  Zij = Xij(fi)
                  

                  它给了我这个错误 TypeError: 'function' object does not support item assignment

                  为什么?我该如何解决这个问题?

                  Why? and how do I solve this?

                  推荐答案

                  你的问题就在这里:

                  Xij[i,j] = ai[i] * Nij[i,j]
                  

                  你命名了一个变量Xij,同时也是一个函数.此外,当您命名函数时,它会覆盖变量.

                  You named a variable Xij, but also a function. Furthermore, when you named the function, it overwrote the variable.

                  因此,当您尝试对函数进行索引并为其分配项目时,会生成错误,因为您无法对函数执行此操作.下面是一个例子:

                  Because of this, when you try to index the function and assign its items, an error is generated because you can't do that on the function. Below is an example:

                  >>> def test(): print "Hi"
                  ...
                  >>> test[1] = "yo!"
                  Traceback (most recent call last):
                    File "<stdin>", line 1, in <module>
                  TypeError: 'function' object does not support item assignment
                  >>>
                  

                  这个错误看起来很眼熟吗?它与您生成的相同,因为我所做的正是您所做的.

                  Does that error look familiar? It is the same one you generated because I did exactly what you did.

                  要解决此问题,请将函数名称更改为 Xij 以外的名称.这样做会使 Xij 等于矩阵,这将支持索引和项分配.

                  To fix this problem, change the name of you function to something other than Xij. Doing so will make Xij equal the matrice, which will support indexing and item assignment.

                  这篇关于“TypeError: 'function' 对象不支持项目分配"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:从 Pandas 列中添加和减去的 for 循环 下一篇:Python:替换嵌套字典中的值

                  相关文章

                • <tfoot id='UjBgh'></tfoot>

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

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

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

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