Arrays | NumPy | Python Methods and Functions

Let`s take a look at some methods for summing a list and a return list.

** Method # 1: ** Using the Naive Method

` ` |

** Exit : **

Initial List - [[1, 2, 3], [4, 5, 6], [7, 8, 9]] final list - [12, 15, 18]

** Method # 2: ** Using the NumPy Array

` # Python code for demonstration `

` # sum of the list list `

` # using array functions `

` import `

` numpy as np `

` `

` # Announcement list start list `

` List `

` = `

` np. array ([[`

` 1 `

`, `

` 2 `

`, `

` 3 `

`], `

` `

` [`

` 4 `

`, `

` 5 `

`, `

` 6 `

`], `

` [`

` 7 `

`, `

` 8 `

`, `

` 9 `

`]]) `

` # Print list of list `

` print `

` (`

` "Initial List -" `

`, `

` str `

` (`

` List `

`)) `

` # Using sum `

` res `

` = `

` np. `

` sum `

< code class = "plain"> ( ` List `

`, `

` 0 `

`) `

` `

` # print result `

` print `

` (`

` "final list -" `

`, `

` str `

` (res)) `

` `

** Exit:**

Initial List - [[1 2 3] [4 5 6] [7 8 9]] final list - [12 15 18]

** Method # 3: ** Using ` zip () `

and list comprehension

` ` |

** Exit :**

Initial List - [[1, 2, 3], [4, 5, 6], [7, 8, 9]] final list - [12, 15, 18]

The field of Artificial Intelligence (AI), which can definitely be considered to be the parent field of deep learning, has a rich history going back to 1950. While we will not cover this history in mu...

23/09/2020

Python Crash Course is the world's best-selling guide to the Python programming language. This quick and in-depth introduction to Python programming will get you started writing programs, solving prob...

11/08/2021

For many decades, some powerful trends have been in place. Computer hardware has rap- idly been getting faster, cheaper and smaller. Internet bandwidth (that is, its information carrying capacity) has...

23/09/2020

While there is no arguing about the staying power of the cloud model and the benefits it can bring to any organization or government, mainstream adoption depends on several key variables falling into ...

10/07/2020

X
# Submit new EBook