AttributeError: module 'numpy' has no attribute 'matlib'
This was already answer here.
This is because
numpy.matlib
is an optional sub-package ofnumpy
that must be imported separately. When you import justnumpy
without the sub-packagematlib
, then Python will be looking for.matlib
as an attribute of thenumpy
package. This attribute has not been assigned tonumpy
without importing numpy.matlib
Related videos on Youtube
![Mikhail Genkin](https://i.stack.imgur.com/3XqU1.jpg?s=256&g=1)
Comments
-
Mikhail Genkin about 2 years
I recently started coding in Python. In the beginning of my scripts I always have the following import:
import numpy as np
.In one of my scripts, I use
np.matlib.repmat
function. It used to work ok, however recently it fails to run showing the following error:AttributeError: module 'numpy' has no attribute 'matlib'
I searched SO for this problem, and it looks like the error like this arises if one has a script called numpy.py in his working directory or if the installed version is different and does not contain the called module.
I didn't name any file numpy.py. I also found out that after I call:
from numpy import matlib as mb
I can use
mb.repmat
. Therefore, my numpy module does containmatlib
module. Can someone hint me, why I cannot callnp.matlib
? -
Mikhail Genkin about 6 yearsGotcha! I'll close my question. Didn't find this answer. Thanks
-
roganjosh about 6 yearsIf it's already answered in such detail as the link you shared, you should flag as a duplicate.
-
TwistedSim about 6 yearsJust done that, I found out how to do it after posting, sorry