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 6946443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:33:57+00:00 2026-05-27T13:33:57+00:00

I am trying to find how to apply two functions to a numpy array

  • 0

I am trying to find how to apply two functions to a numpy array each one only on half the values.
Here is the code I have been trying

def hybrid_array(xs,height,center,fwhh):
    xs[xs<=center] = height*np.exp((-(xs[xs<=center]-center)**2)/(2*(fwhh/(2*np.sqrt(2*np.log(2))))**2))
    xs[xs>center] = height*1/(np.abs(1+((center-xs[xs>center])/(fwhh/2))**2))
    return xs

However I am overwriting the initial array that is passed to the argument. The usual trick of copying it with a slice ie. the following still changes b.

a = b[:]
c = hybrid_array(a,args)

If there is a better way of doing any part of what I am trying, I would be very grateful if you could let me know as I am still new to numpy arrays.
Thank you

  • 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-05-27T13:33:58+00:00Added an answer on May 27, 2026 at 1:33 pm

    Try copy.deepcopy to copy the array b onto a before calling your function.

    import copy
    a = copy.deepcopy(b)
    c = hybrid_array(a,args)
    

    Alternatively, you can use the copy method of the array

    a = b.copy()
    c = hybrid_array(a,args)
    

    Note***

    You may be wondering, why despite an easier way to copy an array with the copy method of numpy array I introduced the copy.deepcopy. Other’s may disagree but here is my reasoning

    1. Using the method deepcopy makes it clear that you are intending to do a deepcopy instead of reference copy
    2. All python’s data type do not support the copy method. Numpy has it and good it has but when you are programming with numpy and python you may end up using various numpy and non numpy data types not all of which would support the copy method. To remain consistent I would prefer to use the first.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to find the sqlserver adapter for rails on windows. I have tried getting
Trying to find a good name for a method swapping each coordinate X and
I'm trying to get two Divs to sit side by side. I want one
I'm trying to isolate duplicates in a 500MB database and have tried two ways
I've spent two days on this and have gotten nowhere. I'm trying to use
Im trying to get two alpha-24 transparent .png files to crossfade into each other.
I have been searching online for awhile, trying to find the best way to
I am trying to work out (or find) a button that looks half decent
I'm trying to apply BlendModes to a GreyScale image in order to have reusable
Trying to find some simple SQL Server PIVOT examples. Most of the examples that

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.