import numpy as np
mat = np.matlib.identity(3,dtype=float)
print mat
出现错误
Traceback (most recent call last):
File "<input>", line 1, in <module>
AttributeError: 'module' object has no attribute 'matlib'
原因在于numpy的__init__.py中并没有引入matlib,所以无法直接使用np.matlib。
修改如下
import numpy.matlib
mat = np.matlib.identity(3,dtype=float)
print mat
第一行直接引入numpy.matlib,这样就可以使用matlib中的函数了。
matlib是一个新的包,只有这样引入才不会错。