分配具有不匹配尺寸的数组时没有ValueError?

时间:2016-09-20 21:17:36

标签: python numpy

Condider以下代码:

Warning: require(/Kurt/Website/appengine-php-wordpress-starter-project/wordpress/index.php): failed to open stream: No such file or directory in /home/kurt/Downloads/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/php/setup.php on line 147

Fatal error: require(): Failed opening required '/Kurt/Website/appengine-php-wordpress-starter-project/wordpress/index.php' (include_path='.:/Kurt/Website/appengine-php-wordpress-starter-project:/home/kurt/Downloads/google-cloud-sdk/platform/google_appengine/php/sdk') in /home/kurt/Downloads/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/php/setup.php on line 147

在带有numpy 1.7.1的python 2.7.5上,这会产生:

import numpy as np

a = np.array([[1,2,3], [4,5,6]])
try:
    a[1,:] = (1,2,3,4)
    print "Value OK"
except ValueError:
    print "Value error"

在带有numpy 1.11.0的python 2.7.12上,这会产生:

Value OK

由于尺寸不匹配,我期待后者。这只是numpy 1.7.1中的一个错误,还是我不应该依赖于ValueError?

作为一个注释:它看起来像某种懒惰的评估问题。 numpy 1.7.1最终会引发错误,但只有当你稍后尝试访问数组时...有人可以解释发生了什么吗?

0 个答案:

没有答案