Why does the AttributeError occur?

0 votes
When I import the following:

import scipy # happens with several other modules, too. I took scipy as an example now...

matrix = scipy.sparse.coo_matrix(some_params)

Why does it produce the following error:

AttributeError: 'module' object has no attribute 'sparse'
Dec 4, 2018 in Python by ana1504.k
• 7,430 points
71 views

1 answer to this question.

0 votes
This happens because the scipy module doesn't have any attribute named sparse. That attribute only gets defined when you import scipy.sparse.

Submodules don't automatically get imported when you just import scipy; you need to import them explicitly. The same holds for most packages, although a package can choose to import its own submodules if it wants to.
answered Dec 4, 2018 by SDeb
• 12,280 points

Related Questions In Python

0 votes
1 answer

What exactly does the .join() method do?

Look carefully at your output: 5wlfgALGbXOahekxSs9wlfgALGbXOahekxSs5 ^ ...READ MORE

answered May 30, 2018 in Python by charlie_brown
• 7,710 points
15 views
+1 vote
1 answer

Why does x,y = zip(*zip(a,b)) work in Python?

I'm extremely new to Python so this ...READ MORE

answered Aug 23, 2018 in Python by Priyaj
• 56,160 points
38 views
0 votes
1 answer

How does Python know whether a variable in the class is a method or a variable?

In python objects/variables are wrapped into methods ...READ MORE

answered Sep 18, 2018 in Python by ariaholic
• 7,320 points
37 views
0 votes
1 answer

How does the @property decorator work?

The property() function returns a special descriptor object: >>> property() <property object ...READ MORE

answered Sep 19, 2018 in Python by Priyaj
• 56,160 points
39 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 128 views
0 votes
1 answer

What does the return statement do in Python?

The print() function is use to write ...READ MORE

answered Oct 1, 2018 in Python by SDeb
• 12,280 points
46 views
0 votes
1 answer

Does Python's time.time() return the local or UTC timestamp?

The time.time() function returns the number of seconds since ...READ MORE

answered Oct 5, 2018 in Python by SDeb
• 12,280 points
18 views