Python Weekly: NumPy Basics (NumPy Arrays)- Part 1

Numpy arrays
NumPy Array

NumPy is a powerful linear algebra library for Python.NumPy is also incredibly fast, as it has bindings to C libraries. It is the core library for scientific computing in Python. It provides a high-performance multidimensional array object and tools for working with these arrays.



Using Numpy

Once installed, we can import the NumPy dependency as

NumPy Arrays

NumPy arrays come in 2 flavors. Vectors and matrices. Vectors are strictly 1-dimensional arrays and matrices are n-dimensional arrays.

Creating NumPy Arrays

From Python list

output : array([1,2,3,4])

output : array([[1,2,3,4],[5,6,7,8,9],[10,11,12,13]])

Built-In Methods

NumPy provides a lot of built-in methods to generate arrays.


It generates evenly spaced values within a given interval.

output : array([0,1,2,3,4,5,6,7,8,9])

output : array([0,2,4,6,8,10])

Zeros and Ones

It generates an array of given shape filled with zeros

output : array([0.,0.,0.,0.])

output : array([[0.,0.,0.,0.],




output : array([1.,1.,1.,1.])

output : array([[1.,1.,1.,1.],





It generates an array with an evenly spaced interval.

output : array([ 0., 5., 10.])

output : array([0. , 0.25, 0.5 , 0.75, 1. , 1.25, 1.5 , 1.75, 2. , 2.25, 2.5 ,
2.75, 3. , 3.25, 3.5 , 3.75, 4. , 4.25, 4.5 , 4.75, 5. ])


It generates an identity matrix.

output : array([





There are more ways to generate random number arrays. And there are some array attributes and methods that will prove useful in day to day life working with NumPy arrays.

Stay tuned for the next part ………

Thank you for taking the time and reading the article. Hope you will appreciate it.



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