You need to install Numpy to work with Arrays in Python. I have shared how to install Numpy, and how to work with Arrays.
Check out how to download NUMPY, and install using the “import NumPy as np” command. After the installation, check Numpy installed correctly.
I am very enthusiastic to try new things. Using Numpy I did a small experiment. As I have mentioned the ‘NumPy’ is a python package used very much in data analytics.
Operation on Arrays in Python
- You can create an array
- Mathematical operations like-add, Subtract, Multiply, and Division you can do on arrays
- You can join two arrays
- You can Copy one array to other
- Read and Write of Array data onto Files
- You can create Structured Arrays
- Vectorization of array elements also possible
- You can covert an array of “m” dimensions into “n” dimensions
1). How to Declare an Array
Using Python array function, now I am defining an array
array() >>>a = np.array([1,2,3,5]) >>>a >>>type(a)
The type() function tells you the type of an array.
How to get Dimension of an Array in Python. Explained with the best example.
Also You May Like : Top Libraries You Need for Data Analytics
2). How to Use Mathematical Operations on Arrays in Python
You can do Addition, Subtraction, Multiply, Division on arrays
You can also get the index of each element. Index starts with ‘0’. So, to get an element of the second index is ‘3’.
3). How to JOIN Two Arrays
You can join arrays either horizontal stacking or vertical stacking. Use vstack() or hstack().
4). How to Copy Data from One Array to Other
You can copy data of one array to another. Explained the best example.
5). How to Write Data From an Array to a File
You can write data of an array into a file. There are two functions. One is save() and the other one is load().
The file which is saved will have the extension’.npy’
6). How to Create a Structured Array
Creating more complex arrays is called “structured arrays”. In an array, you can give of value with any data type.
7). What is an Array Vectorization
Vectorization is the absence of an explicit loop during the development of the code. These loops actually cannot be omitted, but are implemented internally and then are replaced by other constructs in the code.
The application of vectorization leads to a more concise and readable code, and you can say that it will appear more “Pythonic” in its appearance.
In fact, thanks to the vectorization, many operations take on a more mathematical expression. For example, NumPy allows you to express the multiplication of two arrays as shown:
a * b
Or even two matrices:
A * B
8). How to Modify Dimension of an Array
I want to tell you the best example. Suppose you created an array of 4×4. You can split the same array as 2×2. This is called change of array dimension.
Don’t Forget to Share This Post!