# How to Work with Arrays in Python

Here are the operations that you can do with Arrays. Just install Numpy in your machine to work with python arrays.

using the “import NumPy as np” command. After the installation, check Numpy installed correctly.

With Numpy I did a small experiment. You may aware that ‘NumPy’ is a python package used in analytics.

## 8 Python Array Operations

1. Create an array
2. Mathematical operations like-add, Subtract, Multiply, and Division you can do on arrays
3. You can join two arrays
4. You can Copy one array to other
5. Read and Write of Array data onto Files
6. You can create Structured Arrays
7. Vectorization of array elements also possible
8. Slicing an Array

### 1. Declare

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. Addition, Subtraction, Multiply & Division

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. JOIN Two Arrays

You can join arrays either horizontal stacking or vertical stacking. Use vstack() or hstack().

### 4. COPY Array to Array

You can copy data of one array to another. Explained the best example.

### 5. COPY Array to 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. Structured Array

Creating more complex arrays is called “structured arrays”. In an array, you can give of value with any data type.

### 7. 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 * bOr even two matrices:A * B`

### 8. Slicing 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.

Related Posts
{"ft_lang_label":"__label__en","ft_lang_prob":0.8687408,"math_prob":0.62918174,"size":2618,"snap":"2022-05-2022-21","text_gpt3_token_len":611,"char_repetition_ratio":0.13121653,"word_repetition_ratio":0.0,"special_character_ratio":0.2303285,"punctuation_ratio":0.123574145,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99176794,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-05-28T01:52:29Z\",\"WARC-Record-ID\":\"<urn:uuid:dc174f12-c113-49ec-aa3a-cc7d437b6af2>\",\"Content-Length\":\"119549\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:1c7b56a9-338d-4294-8cfd-9617d2eee700>\",\"WARC-Concurrent-To\":\"<urn:uuid:53ce6422-84d7-46e8-8442-893243c11d4b>\",\"WARC-IP-Address\":\"192.0.78.25\",\"WARC-Target-URI\":\"https://srinimf.com/2020/01/09/ideas-on-python-arrays-how-to-use-numpy-correctly/\",\"WARC-Payload-Digest\":\"sha1:K75FCEAIFUCHHWZ536I6DIUB5VWMULCR\",\"WARC-Block-Digest\":\"sha1:UOR4YSB6U5D7JHH3PWDDJMOYDDCOQZHC\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-21/CC-MAIN-2022-21_segments_1652663011588.83_warc_CC-MAIN-20220528000300-20220528030300-00111.warc.gz\"}"}