Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Summary

Summary Numpy Library in Data Science using python

Rating
-
Sold
-
Pages
18
Uploaded on
07-01-2023
Written in
2022/2023

This document provides a good summary to the most important functions in Numpy library in python to those who are interested in Data Science

Institution
Course

Content preview

numpy - Jupyter Notebook http://localhost:8888/notebooks/numpy/numpy.ip




import
In [2]: import numpy as np




1D array
In [45]: a1 = np.array([1,2,3]) # 1 2 3 1D array 1 row and 3 columns shape=(1,3)
type(a1)


Out[45]: numpy.ndarray


In [7]: a1.shape

Out[7]: (3,)



2D array
In [46]: a2= np.array([[1,1,1],[2,2,2]]) # 1 1 1
# 2 2 2 2rows and 3 columns shape = (2,3
a2.shape

Out[46]: (2, 3)



3D array
In [29]: a3 = np.array([[[1,1,1], # This is how it looks
[2,2,2], # 4 4 4 # back 2D
[3,3,3]], # 5 5 5
# 6 6 6



[[4,4,4], # 1 1 1
[5,5,5], # 2 2 2
[6,6,6] # 3 3 3 # front 2D

]])
a3.shape

Out[29]: (2, 3, 3)




1 of 18 1/6/2023, 5:24

,numpy - Jupyter Notebook http://localhost:8888/notebooks/numpy/numpy.ip




In [10]: a3.dtype

Out[10]: dtype('int32')



to check the number of dimensions
In [11]: a1.ndim,a2.ndim,a3.ndim

Out[11]: (1, 2, 3)



to get the size of the array (number of
elements)
In [12]: a1.size,a2.size,a3.size

Out[12]: (3, 6, 18)



converting an arrray to a DF
In [13]: import pandas as pd
df= pd.DataFrame(a2)

In [14]: df


Out[14]: 0 1 2

0 1 1 1

1 2 2 2




creating an arrays

zeros/ones




2 of 18 1/6/2023, 5:24

,numpy - Jupyter Notebook http://localhost:8888/notebooks/numpy/numpy.ip



In [15]: zeros =np.zeros((2,4))
zeros

Out[15]: array([[0., 0., 0., 0.],
[0., 0., 0., 0.]])

In [16]: zeros.shape

Out[16]: (2, 4)


In [17]: type(zeros
)

Out[17]: numpy.ndarray


In [18]: zeros.dtype

Out[18]: dtype('float64')


In [19]: ones=np.ones((2,4))
ones

Out[19]: array([[1., 1., 1., 1.],
[1., 1., 1., 1.]])

In [20]: ones.size


Out[20]: 8



Creating an array with a cerain range
In [21]: array_range = np.arange(0,10,2) # creates an array from 0 to 10(not included )
array_range

Out[21]: array([0, 2, 4, 6, 8])



Creating a random array of a given shape
In [3]: random_array= np.random.randint(0,10,size=(2,4)) # creates a 2D array of shpe
random_array

Out[3]: array([[3, 5, 3, 2],
[4, 7, 2, 0]])




3 of 18 1/6/2023, 5:24

Written for

Institution
Course

Document information

Uploaded on
January 7, 2023
Number of pages
18
Written in
2022/2023
Type
SUMMARY

Subjects

$3.59
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
shamelradwan

Get to know the seller

Seller avatar
shamelradwan I dont
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
3 year
Number of followers
0
Documents
3
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions