Python error only size-1 arrays can be converted to Python scalars

0 votes

I'm trying to plot the exponential and logistic population models, but my code doesn't seem to work as well as I planned, what's wrong?

Full Code:

import numpy as np
import matplotlib.pyplot as plt 
import math
from IPython.display import clear_output\

print ("Utilize Which Growth Model of Population? (Type A or B)") ;
print () ;
print ("A Exponential Growth Model") ;
print ("B Logistic Growth Model") ;
print () ;
A = int(1) ; #Exponential Growth Model
B = int(2) ; #Logistic Growth Model
C = input("Growth Model of choice : ") ;
print () ; 

if C == 'A' :
#Definition of Parameters
    print ("The Differential Equation of your chosen growth model is P'(t) = r*P(t)") ;
    print () ;
    print ("Where r = growth parameter") ;
    print ("Where P(t) = total population at a certain time t") ;
    print ("Where t = time") ; 
    print () ; 
#Explanation of Differential Equation
    print ("This equation can be considered as the exponential differential equation") ; 
    print ("because its solution is P(t) = P(0)*e^r*t ; where P(0) = Initial Population") ;
    print () ; 
    print ("This equation can be portrayed by using this graph : ")    
#Graph Code
    x,y = np.meshgrid (np.linspace(-50, 50, 10), np.linspace(-50, 50, 10)) ;
    r = float (input ("Encode Growth Parameter :")) ;
    t = float (input ("At how many years do you want to solve? :")) ;
    P = float (input ("Encode Population Count :")) ;
    P = y ; 
    t = x ;
    x = np.asarray (x, dtype='float64')
    Un = (P/P*(math.exp(r*t))) #Stack_overflow help from Adam.Er8 
    Vn = (P/P*(math.exp(r*t))) #Stack_overflow help from Adam.Er8 
    plt.quiver (x, y, Un, Vn) ;
    plt.plot ([8, 12, 25, 31], [1, 16, 20, 40]) ;
    plt.show () 

if C == 'B' :
    print ("The Differential Equation of your chosen growth model is y' = k*y*(M-y)") ;
    print () ;
    print ("Where k = slope of the function") ;
    print ("Where y = y-value at the specific point") ;
    print ("Where M = limit of y as x approaches infinity") ;
    print () ;
    print ("This equation is derived using *** ") ; 

    

Jul 9, 2019 in Python by JTM
1,793 views
Hey @JTM, python does not have semicolons. All your print statements have semicolons. Remove them. Also, can you be more specific with "my code doesn't seem to work as well as I planned"?

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

Pyplot error "only size-1 arrays can be converted to Python scalars"

You can plot the chart by taking ...READ MORE

answered Jan 28, 2019 in Python by Omkar
• 69,220 points
9,471 views
0 votes
0 answers

Pyplot error "only size-1 arrays can be converted to Python scalars"

I am getting the following error while ...READ MORE

Nov 28, 2019 in Python by Sumit
• 130 points
3,736 views
0 votes
0 answers

TypeError: only size-1 arrays can be converted to Python scalars

This is my code for key in bboxes: bbox ...READ MORE

May 19, 2020 in Python by Rumia
• 120 points

edited May 19, 2020 by Gitika 1,594 views
+1 vote
0 answers

TypeError: only integer scalar arrays can be converted to a scalar index

import cv2 import numpy as np import matplotlib.pyplot as ...READ MORE

Dec 18, 2019 in Python by sandeep
• 130 points
7,372 views
0 votes
0 answers
0 votes
1 answer

Python error "ValueError: size needs to be (int width, int height)" while using pygame.Surface

pygame.Surface takes in integer values for building ...READ MORE

answered Jun 19, 2019 in Python by Varsha
5,738 views
0 votes
2 answers
+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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,434 views
0 votes
1 answer
+5 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,790 points
4,071 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP