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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:15:20+00:00 2026-05-12T16:15:20+00:00

I would like to provide all mathematical functions for the number-like objects created by

  • 0

I would like to provide “all” mathematical functions for the number-like objects created by a module (the uncertainties.py module, which performs calculations with error propagation)—these objects are numbers with uncertainties.

What is the best way to do this?

Currently, I redefine most of the functions from math in the module uncertainties.py, so that they work on numbers with uncertainties. One drawback is that users who want to do from math import * must do so after doing import uncertainties.

The interaction with NumPy is, however, restricted to basic operations (an array of numbers with uncertainties can be added, etc.); it does not (yet) include more complex functions (e.g. sin()) that would work on NumPy arrays that contain numbers with uncertainties. The approach I have taken so far consists in suggesting that the user define sin = numpy.vectorize(math.sin), so that the new math.sin function (which works on numbers with uncertainties) is broadcast to the elements of any Numpy array. One drawback is that this has to be done for each function of interest by the user, which is cumbersome.

So, what is the best way to extend mathematical functions such as sin() so that they work conveniently with simple numbers and NumPy arrays?

The approach chosen by NumPy is to define its own numpy.sin, rather than modifying math.sin so that it works with Numpy arrays. Should I do the same for my uncertainties.py module, and stop redefining math.sin?

Furthermore, what would be the most efficient and correct way of defining sin so that it works both for simple numbers, numbers with uncertainties, and Numpy arrays? My redefined math.sin already handles simple numbers and numbers with uncertainties. However, vectorizing it with numpy.vectorize is likely to be much slower on “regular” NumPy arrays than numpy.sin.

  • 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-12T16:15:21+00:00Added an answer on May 12, 2026 at 4:15 pm

    It looks like following what NumPy itself does keeps things clean: “extended” mathematical operations (sin…) that work on new objects can be put in a separate name space. Thus, NumPy has numpy.sin, etc. These operations are mostly compatible with those from math, but also work on NumPy arrays.

    Therefore, it seems to me that mathematical functions that should work on usual numbers and NumPy arrays and their counterparts with uncertainties are best defined in a separate name space. For instance, the user could do:

    from uncertainties import sin
    

    or

    from uncertainties import *  # sin, cos, etc.
    

    For optimization purposes, an alternative might be to provide two distinct sets of mathematical functions: those that generalize functions to simple numbers with uncertainties, and those that generalize them to arrays with uncertainties:

    from uncertainties.math_ops import *  # Work on scalars and scalars with uncertainty
    

    or

    from uncertainties.numpy_ops import *  # Work on everything (scalars, arrays, numbers with uncertainties, arrays with uncertainties)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 193k
  • Answers 193k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can extract the user id without a API call,… May 12, 2026 at 6:35 pm
  • Editorial Team
    Editorial Team added an answer Are you using "automatically generate", or "use precompiled header" on… May 12, 2026 at 6:35 pm
  • Editorial Team
    Editorial Team added an answer Can you just compare the size of the disk image… May 12, 2026 at 6:35 pm

Related Questions

I would like to take advantage of all the goodness of the newer Vector
UPDATE: I recently learned from this question that in the entire discussion below, I
I would like to design a web app that allows me to sort, browse,
I would like to authenticate username and passwords for my application on a windows
DTO I'm building a Web application I would like to scale to many users.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.