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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:18:04+00:00 2026-06-17T12:18:04+00:00

long time reader, first time writer. I searched around on google and stack overflow,

  • 0

long time reader, first time writer.

I searched around on google and stack overflow, but wasn’t really able to find a general answer to this question.

I am getting an “unsupported operand type(s) for *: ‘numpy.ndarray’ and ‘numpy.float64′” error in python 2.7.3 using numpy 1.6.2.

The error comes from multiplying a numpy array and a numpy float, but it doesn’t happen every time.

For example:

x = np.tan(1) # numpy.float64
y = np.array([0,1,2,3]) # numpy.ndarray
np.multiply(x,y) # works no problem

Or

x = np.tan(np.abs(np.multiply(-31,41)))  # numpy.float64
y = np.square(np.add(np.divide(np.zeros(100),42),(-27)**40)) # numpy.ndarray
np.multiply(x,y) # works no problem

Both work

Now for the problem children:

np.multiply(np.square(np.add(np.divide(np.zeros(100),42),-27)**40)),
np.tan(np.abs(np.multiply(-31,41))))

or, with x defined as above:

np.multiply(np.square(np.add(np.divide(np.zeros(100),42),(-27)**40)),x)

both produce the error: NotImplemented

I know the random functions and numbers seem odd, but conceptually this still should work, as it worked when both were set to variables individually.

Why does this happen? How can I fix it in a general sense?

Thanks so much!
Jason

  • 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-17T12:18:05+00:00Added an answer on June 17, 2026 at 12:18 pm

    I suspect that the problem here is that NumPy cannot store Python long values in its arrays. As soon as you try to do this, it switches the data type of the array to object. Arithmetic operations on the array then become trickier because NumPy can no longer do the arithmetic itself.

    >>> np.array(27**40)
    array(1797010299914431210413179829509605039731475627537851106401L, dtype=object)
    >>> np.array(27**40) * np.tan(1)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: unsupported operand type(s) for *: 'numpy.ndarray' and 'numpy.float64'
    

    Oddly enough, swapping the order of the arguments can sometimes work:

    >>> np.tan(1) * np.array(27**40)
    2.7986777223711575e+57
    

    In this second case, the type of the result is a Python float, not a NumPy array.

    The fix is to avoid creating long values in NumPy arrays, and use floats instead:

    >>> np.array(27.0**40)
    array(1.797010299914431e+57)
    >>> np.array(27.0**40) * np.tan(1)
    2.7986777223711575e+57
    >>> np.multiply(np.square(np.add(np.divide(np.zeros(10),42),(-27.0)**40)),np.tan(1))
    array([  5.02925269e+114,   5.02925269e+114,   5.02925269e+114,
             5.02925269e+114,   5.02925269e+114,   5.02925269e+114,
             5.02925269e+114,   5.02925269e+114,   5.02925269e+114,
             5.02925269e+114])
    

    If you do get an error like this is the future, the first thing to do is to check the dtype of the array being multiplied. Does it contain NumPy values or Python objects?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Long time reader, first time poster asks: After many weeks of google and forum
First time poster, long time reader. I searched and found no questions that answered
Howdy -- Long time reader, first time questioner. :) I could really use some
Hey! First post for me but long time reader of Stackoverflow. Anyway, got a
I already searched a long time for a good solution, but I can't find
long time reader, first time writer here. I'm trying to figure out all possible
I've been long time reader, but this is my first time posting. Ok, so
long time reader first time user. I'm putting together my first RoR application and
Long time reader, first time poster. Any help is greatly appreciated. I have crafted
(Long time reader of SO, first time asking a q. I'm quite new to

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.