Function array()
In fact, there are various functions in NumPy for creating arrays. Now, we'll explore one of the most commonly used ones, namely np.array()
. Below, you'll find an example of how to use this function:
Let's now determine the type of object that this function creates. We can do this using the well-known function type()
.
Note
The
type()
function takes an object of any type and returns its type. The argument can indeed be of any type: number, string, list, dictionary, tuple, function, class, module, etc.
We can see the type of the created array is ndarray
. But what does that mean?
ndarray - This object is a multidimensional homogeneous array with a predetermined number of elements.
Now it's time to practice!
Task
- You have to create two NumPy arrays. The first one should look like this:
[65, 2, 89, 5, 0, 1]
and the second one should look like this:[1, 2, 3]
. - Display these arrays on the screen.
- Display the type of these arrays on the screen.
Everything was clear?
Course Content
NumPy in a Nutshell
NumPy in a Nutshell
1. Getting Started with NumPy
4. Important Functions
Function array()
In fact, there are various functions in NumPy for creating arrays. Now, we'll explore one of the most commonly used ones, namely np.array()
. Below, you'll find an example of how to use this function:
Let's now determine the type of object that this function creates. We can do this using the well-known function type()
.
Note
The
type()
function takes an object of any type and returns its type. The argument can indeed be of any type: number, string, list, dictionary, tuple, function, class, module, etc.
We can see the type of the created array is ndarray
. But what does that mean?
ndarray - This object is a multidimensional homogeneous array with a predetermined number of elements.
Now it's time to practice!
Task
- You have to create two NumPy arrays. The first one should look like this:
[65, 2, 89, 5, 0, 1]
and the second one should look like this:[1, 2, 3]
. - Display these arrays on the screen.
- Display the type of these arrays on the screen.
Everything was clear?