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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:18:56+00:00 2026-05-11T16:18:56+00:00

Surely a 0d array is scalar, but Numpy does not seem to think so…

  • 0

Surely a 0d array is scalar, but Numpy does not seem to think so… am I missing something or am I just misunderstanding the concept?

>>> foo = numpy.array(1.11111111111, numpy.float64)
>>> numpy.ndim(foo)
0
>>> numpy.isscalar(foo)
False
>>> foo.item()
1.11111111111
  • 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-11T16:18:56+00:00Added an answer on May 11, 2026 at 4:18 pm

    One should not think too hard about it. It’s ultimately better for the mental health and longevity of the individual.

    The curious situation with Numpy scalar-types was bore out of the fact that there is no graceful and consistent way to degrade the 1×1 matrix to scalar types. Even though mathematically they are the same thing, they are handled by very different code.

    If you’ve been doing any amount of scientific code, ultimately you’d want things like max(a) to work on matrices of all sizes, even scalars. Mathematically, this is a perfectly sensible thing to expect. However for programmers this means that whatever presents scalars in Numpy should have the .shape and .ndim attirbute, so at least the ufuncs don’t have to do explicit type checking on its input for the 21 possible scalar types in Numpy.

    On the other hand, they should also work with existing Python libraries that does do explicit type-checks on scalar type. This is a dilemma, since a Numpy ndarray have to individually change its type when they’ve been reduced to a scalar, and there is no way of knowing whether that has occurred without it having do checks on all access. Actually going that route would probably make bit ridiculously slow to work with by scalar type standards.

    The Numpy developer’s solution is to inherit from both ndarray and Python scalars for its own scalary type, so that all scalars also have .shape, .ndim, .T, etc etc. The 1×1 matrix will still be there, but its use will be discouraged if you know you’ll be dealing with a scalar. While this should work fine in theory, occasionally you could still see some places where they missed with the paint roller, and the ugly innards are exposed for all to see:

    >>> from numpy import *
    >>> a = array(1)
    >>> b = int_(1)
    >>> a.ndim
    0
    >>> b.ndim
    0
    >>> a[...]
    array(1)
    >>> a[()]
    1
    >>> b[...]
    array(1)
    >>> b[()]
    1
    

    There’s really no reason why a[...] and a[()] should return different things, but it does. There are proposals in place to change this, but looks like they forgot to finish the job for 1×1 arrays.

    A potentially bigger, and possibly non-resolvable issue, is the fact that Numpy scalars are immutable. Therefore “spraying” a scalar into a ndarray, mathematically the adjoint operation of collapsing an array into a scalar, is a PITA to implement. You can’t actually grow a Numpy scalar, it cannot by definition be cast into an ndarray, even though newaxis mysteriously works on it:

    >>> b[0,1,2,3] = 1
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: 'numpy.int32' object does not support item assignment
    >>> b[newaxis]
    array([1])
    

    In Matlab, growing the size of a scalar is a perfectly acceptable and brainless operation. In Numpy you have to stick jarring a = array(a) everywhere you think you’d have the possibility of starting with a scalar and ending up with an array. I understand why Numpy has to be this way to play nice with Python, but that doesn’t change the fact that many new switchers are deeply confused about this. Some have explicit memory of struggling with this behaviour and eventually persevering, while others who are too far gone are generally left with some deep shapeless mental scar that frequently haunts their most innocent dreams. It’s an ugly situation for all.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer My guess would be that you are losing the control… May 11, 2026 at 8:47 pm
  • Editorial Team
    Editorial Team added an answer Turns out this problem was related to another problem I… May 11, 2026 at 8:47 pm
  • Editorial Team
    Editorial Team added an answer I found the problem I was having. I used fiddler… May 11, 2026 at 8:47 pm

Related Questions

Is possible to insert a line break where the cursor is in Vim without
I'm currently modifying a class that has 9 different constructors. Now overall I believe
I was investigating the concept of Multiple Inheritance (it's been almost 10 years since
I'd like to populate the homepage of my user-submitted-illustrations site with the hottest illustrations
I have a question for the clever people of the SO community. Below is

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.