Home > database >  What are Numpy Scalars and Array Scalars
What are Numpy Scalars and Array Scalars

Time:09-23

I am trying to learn NumPy basic concepts but unable to wrap my head around few things. I am following this NumPy documentation

Scalars Python defines only one type of a particular data class (there is only one integer type, one floating-point type, etc.). This can be convenient in applications that don’t need to be concerned with all the ways data can be represented in a computer. For scientific computing, however, more control is often needed. Here Scalars means single value?

In NumPy, there are 24 new fundamental Python types to describe different types of scalars. These type descriptors are mostly based on the types available in the C language that CPython is written in, with several additional types compatible with Python’s types. What python type means here? although its saying its based on C lang types.

Array scalars have the same attributes and methods as ndarrays. This allows one to treat items of an array partly on the same footing as arrays, smoothing out rough edges that result when mixing scalar and array operations. Absolutely not getting what Array scalar is? found this while searching but still confusing

Interestingly, the array scalars can have some array-like attributes. The only missing attribute is ctype.

If array scalars have same attributes as ndarrays? so which one to use?

CodePudding user response:

Here Scalars means single value?

Yes e.g. an int or a float.

What python type means here? although its saying its based on C lang types.

All the things you have in python are of a python type. Functions, floats, classes, datetimes ... . And they are saying the numpy types are based on C types.

Absolutely not getting what Array scalar is?

An array scalar is what you get back if you index into a numpy array. E.g. if you have an array of type float64 and you take out the first value you get an array scalar of type float64 which is different from python's float. See https://stackoverflow.com/a/49581266/2640045

If array scalars have same attributes as ndarrays? so which one to use?

You should use ndarrays. That's the same as numpy arrays btw.. I would consider array scalars as a technicality that you will very rarely have to think about differently than just regular python floats and ints ... .

  • Related