np.dot的尺寸要求是什么?

时间:2019-02-10 20:02:15

标签: python numpy

我有一个变量console.log(JSON.stringify(error)),具有:

<span id="__w2_w6NSrFgH6_contents">Translate Question</span>

另一个变量W具有:

[[1.]
 [2.]
 [3.]
 [4.]
 [5.]]

我一直在猜测和检查如何一起X[[1. 5.1 3.5 1.4 0.2] [1. 4.9 3. 1.4 0.2] [1. 4.7 3.2 1.3 0.2] [1. 4.6 3.1 1.5 0.2] [1. 5. 3.6 1.4 0.2] [1. 5.4 3.9 1.7 0.4] [1. 4.6 3.4 1.4 0.3] [1. 5. 3.4 1.5 0.2] [1. 4.4 2.9 1.4 0.2] [1. 4.9 3.1 1.5 0.1] [1. 5.4 3.7 1.5 0.2] ... [1. 5.7 2.8 4.1 1.3]] 似乎有效,但形状错误:np.dot

我想做的是乘以这样:

np.dot(W.T, X.T)中的每一行

(1, 100)。我该怎么办?

3 个答案:

答案 0 :(得分:3)

矩阵乘法是按列

std::map

所以:

        X
XXXXX   X   .
..... * X = .
.....   X   .
        X

答案 1 :(得分:2)

a 的最后一个尺寸应与 b 倒数第二个尺寸相同。

给出:np.dot(a, b)

更多参考文献:https://stackoverflow.com/a/31287674

答案 2 :(得分:1)

您可以使用np.matmul

class ProfileEditState extends State<ProfileEdit> {
  @override
  Widget build(BuildContext context) {
    return CupertinoTabScaffold(
      tabBar: CupertinoTabBar(
        onTap: (n) {

            // HERE <=============================
            // From here,
            // if the tab icon 1 is clicked,
            // I want to access the Navigator 
            // inside the One() Widget so I can do 
            // Navigator.of(One()).popUntil((x) =>false))
            print("tab number is $n");
        },
        items: <BottomNavigationBarItem>[
          BottomNavigationBarItem(
              icon: Icon(CupertinoIcons.home)),
          BottomNavigationBarItem(icon: Icon(CupertinoIcons.padlock_solid)),
          BottomNavigationBarItem(icon: Icon(CupertinoIcons.padlock_solid)),

        ],
      ),
      tabBuilder: (BuildContext context, int index) {
        switch (index) {
          case 0:
            return One(); // returns a CupertinoTabView
            break;
          case 1:
            return Two();
            break;
          case 2:
            return Three();
            break;
        }
        return null;
      },
    );
  }
}

快速检查输出:

class ProfileEditState extends State<ProfileEdit> {
  @override
  Widget build(BuildContext context) {
    return CupertinoTabScaffold(
      tabBar: CupertinoTabBar(
        onTap: (n) {

            // HERE <=============================
            // From here,
            // if the tab icon 1 is clicked,
            // I want to access the Navigator 
            // inside the One() Widget so I can do 
            // Navigator.of(One()).popUntil((x) =>false))
            print("tab number is $n");
        },
        items: <BottomNavigationBarItem>[
          BottomNavigationBarItem(
              icon: Icon(CupertinoIcons.home)),
          BottomNavigationBarItem(icon: Icon(CupertinoIcons.padlock_solid)),
          BottomNavigationBarItem(icon: Icon(CupertinoIcons.padlock_solid)),

        ],
      ),
      tabBuilder: (BuildContext context, int index) {
        switch (index) {
          case 0:
            return One(); // returns a CupertinoTabView
            break;
          case 1:
            return Two();
            break;
          case 2:
            return Three();
            break;
        }
        return null;
      },
    );
  }
}

请注意,在这种情况下,由于两个输入均为W = np.array([[1.],[2.],[3.],[4.],[5.]]) X = np.array([[1., 5.1, 3.5, 1.4, 0.2], [1., 4.9, 3. , 1.4, 0.2], [1. , 4.7, 3.2, 1.3, 0.2], [1. ,4.6, 3.1, 1.5, 0.2], [1. ,5. , 3.6, 1.4, 0.2], [1. ,5.4, 3.9, 1.7, 0.4]]) np.matmul(X,W) array([[28.3], [26.4], [26.2], [26.5], [28.4], [32.3]]) ,因此它等效于1*1 + 2*5.1 + 3*3.5 + 4*1.4 + 5*0.2 = 28.3