TypeError: unsupported operand type(s) for /: 'list' and 'list'

+1 vote

This is my part of code, why it shows: TypeError: unsupported operand type(s) for /: 'list' and 'list'
<Figure size 576x288 with 0 Axes>

plt.figure(figsize=(8, 4))
plt.scatter(p_vol, p_ret,c=p_ret / p_vol, marker='o')

plt.scatter(t_vol, trets,c=trets / t_vol, marker='x')

plt.plot(statistics(opts['x'])[1], statistics(opts['x'])[0],'r*', markersize=15.0)
# portfolio with highest Sharpe ratio
plt.plot(statistics(optv['x'])[1], statistics(optv['x'])[0],'y*', markersize=15.0)
# minimum variance portfolio
plt.grid(True)
plt.xlabel('expected volatility')
plt.ylabel('expected return')
plt.colorbar(label='Sharpe ratio')
May 17 in Python by anonymous
• 220 points

edited May 18 by Gitika 315 views

Hey, @Noman,

Just check that you have defined plt in your code or not, probably you are getting this error because of that.

Its shows this error everything is fine 

TypeError                                 Traceback (most recent call last)
<ipython-input-334-7d2a34ebfdb9> in <module>
      1 plt.figure(figsize=(8, 4))
----> 2 plt.scatter(p_vol, p_ret,c=p_ret / p_vol, marker='o')
      3                 # random portfolio composition
      4 plt.scatter(t_vol, trets,c=trets / t_vol, marker='x')
      5             # efficient frontier

TypeError: unsupported operand type(s) for /: 'list' and 'list'

<Figure size 576x288 with 0 Axes>

Hey, @Noman,

It might be because you are running the loops for the complete length of data.

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Python

0 votes
1 answer

TypeError: unsupported operand type(s) for -: 'list' and 'int'

Hey, @William For me the code is working ...READ MORE

answered Mar 11 in Python by Roshni
• 3,830 points
633 views
0 votes
1 answer

TypeError: unsupported operand type(s) for -: 'str' and 'str'

Hi. This error is caused because you ...READ MORE

answered May 12, 2019 in Python by Anjali
31,599 views
0 votes
0 answers

TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

Hi guys i have below code . ...READ MORE

Oct 30, 2019 in Python by sumanth
• 190 points
5,661 views
0 votes
1 answer

How to have values from a List1 into Columns Names and List 2 Values as Index for an Empty DataFrame

Try like this, it will give you ...READ MORE

answered Jul 10, 2019 in Python by Cherukuri
• 32,490 points
205 views
+2 votes
3 answers

Write a for loop that prints all elements of a list and their position in the list. a = [4,7,3,2,5,9]

Try using this question by list comprehension: a=[4,7,3,2,5,9] print([x for ...READ MORE

answered Dec 8, 2019 in Python by vinaykumar
• 180 points
6,542 views
+2 votes
0 answers

unsupported operand type error

tech_list=closingdata.pct_change() tech_list READ MORE

Jan 26 in Python by Anupriya
• 140 points
189 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, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,355 views
0 votes
0 answers
+4 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,800 points
1,004 views