How to mix strings and floats in a NumPy array?
I'd consider a pandas DataFrame instead - the actual data is stored as a numpy array and so supports everything it needs to, and the headers are separate so you don't need to do awkward slicing when working on the whole data set. You can also then index rows and columns by their index. And it supports going to and from CSVs easily.
As an aside, the way to get arrays to accept mixed types is
np.array([1, 'a'], dtype=object)
but obviously you lose practically all of the benefits of using numpy in the first place.
More on reddit.comAlgebraic Datatypes and Pattern Matching in Python
Why is this using lisp naming conventions? There are much more user friendly to call these things.
More on reddit.comQuoting the python library reference:
There are four distinct numeric types: plain integers, long integers, floating point numbers, and complex numbers. In addition, Booleans are a subtype of plain integers. Plain integers (also just called integers) are implemented using long in C, which gives them at least 32 bits of precision. Long integers have unlimited precision. Floating point numbers are implemented using double in C. All bets on their precision are off unless you happen to know the machine you are working with.
According to the Python documentation:
The principal built-in types are numerics, sequences, mappings, classes, instances and exceptions.
Numeric Types: int, float, complex
Sequence Types: list, tuple, range
Text Sequence Type: str
Binary Sequence Types: bytes, bytearray, memoryview
Set Types: set, frozenset
Mapping Types: — dict
Other Built-in Types:
Modules, Classes and Class Instances, Functions, Methods, Code Objects, Type Objects, the Null Object (None), the Ellipsis Object, the NotImplemented Object, Boolean Values (True and False), Internal Objects.
Answering your question:
Are integers and float numbers considered to be the same data type?
There are three distinct numeric types: integers, floating point numbers, and complex numbers. Floating point numbers are usually implemented using double in C.
Probably you are a bit confused because mathematically speaking any number of type int and any number of type float belong to the set of the real numbers. The numbers module defines a hierarchy of numeric abstract base classes: Number, Complex, Real, Rational, and Integral. However, none of the types defined in this module can be instantiated.
You can use these classes to check if a specific number is an instance of them:
In[1]: import numbers
In [2]: isinstance(10, numbers.Integral)
Out[2]: True
In [3]: isinstance(10.5, numbers.Integral)
Out[3]: False