Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8972089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:07:44+00:00 2026-06-15T18:07:44+00:00

from numpy import * from pylab import * from math import * def LogisticMap(a,x):

  • 0
from numpy import *
from pylab import *
from math import *

def LogisticMap(a,x):
    return 4.*a*x*(1.-x)

def CosineMap(a,x):
    return a*cos(x/(2.*pi))

def TentMap(a,x):
    if x>= 0 or x<0.5:
        return 2.*a*x
    if x>=0.5 or x<=1.:
        return 2.*a*(1.-x)

a = 0.98
N = 40

xaxis = arange(0.0,N,1.0)

Func = CosineMap

subplot(211)
title(str(Func.func_name) + ' at a=%g and its second iterate' %a)
ylabel('X(n+1)') # set y-axis label
plot(xaxis,Func(a,xaxis), 'g', antialiased=True)

subplot(212)
ylabel('X(n+1)') # set y-axis label
xlabel('X(n)')   # set x-axis label
plot(xaxis,Func(a,Func(a,xaxis)), 'bo', antialiased=True)

My program is supposed to take any of the three defined functions and plot it. They all take in a value x from the array xaxis from 0 to N and then return the value. I want it to plot a graph of xaxis vs f(xaxis) with f being any of the three above functions. The logisticmap function works fine, but for CosineMap i get the error “only length-1 arrays can be converted to python scalars” and for TentMap i get error “The truth value of an array with more than one element is ambiguous, use a.any() or a.all()”. My tent map function is suppose to return 2*a*x if 0<=x<0.5 and it’s suppose to return 2*a*(1-x) if 0.5<=0<=1.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T18:07:46+00:00Added an answer on June 15, 2026 at 6:07 pm

    You first import numpy.cos, and then import math.cos. The latter shadows the former, and doesn’t know how to handle NumPy arrays. Hence the error.

    To fix, try:

    import numpy
    
    def CosineMap(a,x):
        return a*numpy.cos(x/(2.*pi))
    

    Problems of this sort are a good reason to avoid from X import *-style imports.

    As to TentMap, here is one way to vectorize it correctly:

    def TentMap(a,x):
        return 2.*a*numpy.minimum(x, 1.-x)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to plot the following ! from numpy import * from pylab
When I run this simple code: from pylab import * import numpy as np
I found this code on http://matplotlib.sourceforge.net/examples/pylab_examples/quiver_demo.html from pylab import * from numpy import ma
I have this code: from pylab import * from mpl_toolkits.axes_grid.anchored_artists import AnchoredText import numpy
Rather than defining from numpy import cos as cos from numpy import arccos as
I've got Python code with a preamble containing the line: from numpy import array,arccosh,random_integers
What's wrong with this snippet of code? import numpy as np from scipy import
As an example: from numpy import * A = array([2/3., 4]) print A Gives
Suppose you have a 2D curve, given by e.g.: from matplotlib import pylab t
import numpy from numpy import asarray Initial = numpy.asarray [2.0, 4.0, 5.0, 3.0, 5.0,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.