InfinityCodeX

Unlock the power of Python, Data Science, Machine Learning, and Deep Learning with our comprehensive guides! Whether you're a beginner eager to dive into AI or an experienced professional looking to sharpen your skills, our blog offers easy-to-follow tutorials, insightful tips, and expert advice to fuel your AI career. Dive in today and start mastering the cutting-edge technologies shaping the future!
Numpy in Python


NOTE : *python does not have array it is build on list only*

*What is Numpy ?
  • Numpy is used for mathematical & Logical operations on the arrays.
  • It provides features for multi dimensional array & matrices in python too.
  • Numpy has more features than list.
  • The unique thing about Numpy is that you can put list or tuple it will convert it to numpy array.
  • Numpy does not come by default with python if you wanna use it : go to command prompt and type : pip install numpy 
  • It does not come with python by default that's why we are using jupyter because it come's in it.
  • Now go to Anaconda > jupyternotebook > Click on ( New ) > Select Python3
  • Click shift+enter to run the code.


As you all know what what python can do; now it's time to explore it. So go to your jupyter notebook & lets get started. If you don't know what jupyter notebook is then check out my Installing Anaconda blog. 

1.) Creating Numpy array : 

Python numpy support both 1 dimensional as well as 2 dimensional array : 

(i) 1D array :

import numpy as np

a=np.array([1,2,3])

b=np.array((4,5,6))

print(a)

print(b)

>>[1,2,3]

     [4,5,6]

(ii) 2D array :

import numpy as np

a=np.array([[1,2,3],[4,5,6]])

print(a)

>>[[1,2,3]

      [4,5,6]]



As you all see that our output is already converted into the array/List what ever suits you call that.
As you can see it is converted into List & if you read my sequence blog you must be familiar with List & probably know that list's are mutable/editable.
Now this factor of list will be very useful for us; now we can use List in many ways.

(iii) N-D array :
  • Most important object defined in Numpy is an N-Dimension array type called ndarray.
  • In real world we don't use that much array we use max to max 3 dimension's. 
  • Describe collection of items of the same type.
  • Items can be accessed using a zero based index.
  • Every item in an ndarray takes the same size of block in the memory.
  • Each element in ndarray is an object of data-type object (called dtype).

No comments:

No Spamming and No Offensive Language

Powered by Blogger.