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

Related Questions

I have developed about 300 Applications which I would like to provide with multi-language
I would like to provide two different versions of my iPhone app on the
I would like to provide the raw text referring to an environment variable to
I would like to write a utility that will provide me with a relatively
I would like to update a Windows Forms application to provide the following features:
I would like to use the ASP.NET Membership Provider security framework but would like
I am using some features that are provided in GCC v4+ and would like
The DateTimeConverter class provides conversions between DateTime and string. I would also like to
Would like to get a list of advantages and disadvantages of using Stored Procedures.
Would like to create a strong password in C++. Any suggestions? I assume it

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.