The Differences Between Python Lists and Numpy Arrays

# import numpy module
import numpy as np
list_a = [1, 2, 3]
list_b = [4, 5, 6]
# add the corresponding values of each list together# without numpy
sum_list = []
for index in range(3):
sum_list.append(list_a[index] + list_b[index])
# with numpy
sum_array = np.array(list_a) + np.array(list_b)
# find the median of an array
sum_array.median()
>>>7
# return shape of an array
twoDarray = np.array([[1, 2], [3, 4], [5, 6]])
twoDarray.shape>>>(3, 2)# reshape 3x2 array into a 2x3 arraytwoDarray = twoDarray.reshape(2, 3)print(twoDarray.shape)
twoDarray
>>>
(2, 3)
array([[1, 2, 3],
[4, 5, 6]])

--

--

--

Data scientist learning at Flat Iron School

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How Data Science Powers Businesses in 2021

What are the 5 Most Desired Skills employers look for in a Data Scientist?

How to learn Apache Spark

Google Data Analytics Professional Certificate: My Review and Study Notes

A Brief Introduction to ARIMA and SARIMA Modeling in Python

How to create a cool seismic heat map with 20 lines of python code?

Into the data: Day 1

Into the data: Day 1

Using “Big Data” to forecast migration

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Datascience George

Datascience George

Data scientist learning at Flat Iron School

More from Medium

An introduction to multiprocessing in Python

Transpose Matrix using Python — Linear Algebra

Collatz Conjecture with Python