This post is a continuation of this post in which we talk about the basics of creating numpy arrays. In this one we'l talk through a few more examples.
We already know that numpy arrays take a sequence of homogenously typed, all the same data type, data and create a "less memory" optimization of that dataset. We're vectorizing the data set by removing the dynamically typed programming language inherit in python's core and replacing it for the speed of numpy.
To visually see this input of sequence arguments to create rows, let's create a separate list among different python lines and put them all into one array.
I think the easiest representation of creating numpy arrays is to see multiple lists all individually, then placing them into a nest python list. From there, we can input that nested list to the array method and get a numpy array.
When we input lists that contain elements of different data types, without providing the data type that we want as an arguement in the array method, numpy is left to determine this on its own. The default nature of numpy is to find a data type that keeps all the information that it can and fits all the elements. If there's strings as any of the elements, all elements will be strings. If there are no strings, but there are float values, then all the values will be floats. If only integers are present, then we have already seen how numpy will default to ints.
The idea is that numpy doesn't want to lose information by a selection of a default data type. So it will pick the one to keep the most information in the data set, if it can be accurately described in one data type. If not, then we'll get back an error.