Difference between List and Numpy Array

Learn the distinctions between Python lists and Numpy arrays, highlighting Numpy's superior performance and functionality for numerical operations.
20 Videos
No Coding Experience Required
45 Assignments
Self Paced
An abstract design featuring smooth curves and geometric shapes, creating a minimalist aesthetic.

Sign Up For Free

Join now for expert-led courses, hands-on exercises, and a supportive learning community!

Numpy - Numerical Python

#pip install numpy
import numpy as np
x = [1,2,3,4.7,"python"]
x

OUTPUT:

[1, 2, 3, 4.7, 'python']‍

1. Less storage

2. More Speed

 

A List cannot handle mathematical operations.

Numpy array can handle mathematical operations.

x = [1,2,3,4]
y = [4,5,6,7]
x+y

OUTPUT:

[1, 2, 3, 4, 4, 5, 6, 7]
x = np.array([1,2,3,4])
y = np.array([5,6,7,8])
x+y

OUTPUT:

array([ 6,  8, 10, 12])

List is hetrogenous

Array is homogeneous

all the elements should always be the same

x= np.array([1,2,3,5.6,"python"])
x

OUTPUT:

array(['1', '2', '3', '5.6', 'python'], dtype='<U32')
Lesson Assignment
Challenge yourself with our lab assignment and put your skills to test.
# Python Program to find the area of triangle

a = 5
b = 6
c = 7

# Uncomment below to take inputs from the user
# a = float(input('Enter first side: '))
# b = float(input('Enter second side: '))
# c = float(input('Enter third side: '))

# calculate the semi-perimeter
s = (a + b + c) / 2

# calculate the area
area = (s*(s-a)*(s-b)*(s-c)) ** 0.5
print('The area of the triangle is %0.2f' %area)
Sign up to get access to our code lab and run this code.
AI icon

AI Assistant For Help

Enhance your learning experience with our AI Learning Assistant. This sophisticated tool seamlessly evaluates your progress, course materials, and code, providing customized feedback and suggestions on the spot.
development icon

Flexible Mobile Coding

Engage with your coding tasks anytime, anywhere. Our adaptable, mobile optimized IDE lets you execute programming tasks directly from any web enabled device.
web
search icon

Project Development Support

Navigate through project challenges effortlessly with AI- powered support and swift access to a resource- rich community network.
file sharing icon

On-Demand Documentation

Quickly access integrated, context-specific documentation directly within the learning platform, streamlining your study process without the need to switch applications.
An abstract design featuring smooth curves and geometric shapes, creating a minimalist aesthetic.

Ready to become a Data Scientist that industry loves to hire? Apply Now. 

Explore Courses