Skip to main content
Open navigation menu
Close suggestions
Search
Search
en
Change Language, English
Upload
Sign in
Sign in
0 ratings
0% found this document useful (0 votes)
148 views
9 pages
Numpy For Data Science ?
Numpy
Uploaded by
Pankaj Singhi
AI-enhanced title
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download
Save
Save Numpy for Data Science ? For Later
Share
0%
0% found this document useful, Mark this document as useful
0%
0% found this document not useful, Mark this document as not useful
Print
Embed
Report
0 ratings
0% found this document useful (0 votes)
148 views
9 pages
Numpy For Data Science ?
Numpy
Uploaded by
Pankaj Singhi
AI-enhanced title
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Go to previous items
Download
Save
Save Numpy for Data Science ? For Later
Share
0%
0% found this document useful, Mark this document as useful
0%
0% found this document not useful, Mark this document as not useful
Print
Embed
Report
Go to next items
Download
Top 50 Numpy Exercises for Data Science - Cheatsheet . Import the numpy package under the name np (* x import numpy as np . Print the numpy version and the configuration (* ¥ x) print(np._version_) np.show_config() . Create a null vector of size 10 (* x9) Z = [Link](10) print(Z) . How to get the documentation of the numpy add function from the command line? (x vrs) python -c “import numpy; [Link]([Link])" . Create a null vector of size 10 but the fifth value which is 1 (vv) Z = [Link](10) Z{4] =1 print(Z) . Create a vector with values ranging from 10 to 49 (# x Z = [Link](10,50) print(Z) . Reverse a vector (first element becomes last) (* x* v) -arange(50) ri-1]@ © 10. 11, 12, 13. 14. Create a 3x3 matrix with values ranging from 0 to 8 (*¥ Z = [Link](9).reshape(3,3) print(Z) Find indices of non-zero elements from [1,2,0,0,4,0] (* > x) nz = [Link]([1,2,0,0,4,0]) print(nz) Create a 3x3 identity matrix (* >: Z = [Link](3) print(Z) Create a 3x3x3 array with random values (* ¥ Z = [Link]. random((3,3,3)) print(Z) Create a 10x10 array with random values and find the minimum and maximum values (sxx) Z = [Link]. random((10,16)) Zmin, Zmax = [Link](), [Link]() print(Zmin, Zmax) Create a random vector of size 30 and find the mean value (* Z = [Link]. random(30) m = [Link]() print(m) Create a 2d array with 1 on the border and 0 inside (* xr) Z = [Link]((10,10)) Z[l:-1,1:-1] = 015. What is the result of the following expression? (x +r) ® * [Link] [Link] == [Link] [Link] > [Link] [Link] - [Link] 16. Create a 5x5 matrix with values 1,2,3,4 just below the diagonal (*¥ Z = [Link](1+[Link](4),k=-1) print(Z) 17. Create a 8x8 matrix and fill it with a checkerboard pattern (*« Z = [Link]((8,8) ,dtype=int) 2(e12,2:2] = 1 Z[2:2,1::2] = 1 print(Z) 18. Consider a (6,7,8) shape array, what is the index (x,y,z) of the 100th element? print (np.unravel_index(100, (6,7,8))) 19. Create a checkerboard 8x8 matrix using the tile function (* y+) Z = [Link]( [Link]({[0,1],[1,0]]), (4,4) print(Z) 20. Normalize a 5x5 random matrix (* vv) Z = [Link]((5,5)) 2max, Zmin = [Link](), [Link]() Z = (Z - Zmin)/(Zmax'- Zmin) print(Z)21. Create a custom dtype that describes a color as four unisgned bytes (RGBA) (kye xr) r", [Link], 1), Hg" color = [Link](L a [Link], 1), [Link], 1), [Link], 1)]) 22. Multiply a 5x3 matrix by a 3x2 matrix (real matrix product) (+ s+) Z = [Link]([Link]((5,3)), [Link]((3,2))) print (Z) 23. Given a 1D array, negate all elements which are between 3 and 8, in place. (aoe) # Author: Evgeni Burovski Z = [Link](11) ZU(3 < Z) & (Z <= 8)] *= -1 24. What is the output of the following script? (* ¥ +) # Author: Jake VanderPlas print (sum(range(5),-1)) from numpy import * print (sum(range(5),-1)) 25. Consider an integer vector Z, which of these expressions are legal? (* + anez 2<
>2 Z<-Z 1j*Z zl Z
Z26. What are the result of the following expressions? [Link](®) // [Link](0) [Link](0) // [Link](@.) [Link](0) / [Link](@) [Link](0) / [Link](@.) 27. How to round away from zero a float array ? (* vr) # Author: Charles R Harris Z = [Link](-10,+10,10) print ([Link](Z + [Link](®.5, Z))) 28. Extract the integer part of a random array using 5 different methods (* * xr) Z = [Link](0,10,10) print (Z - 2%1) print ([Link](Z)) print ([Link](Z)-1) print ([Link](int)) print ([Link](Z)) 29. Create a 5x5 matrix with row values ranging from 0 to 4 (* >) Z = [Link]((5,5)) Z += [Link](5) print(Z) 30. Consider a generator function that generates 10 integers and use it to build an array (* vr vr) def generate(): for x in xrange(10): yield x Z = [Link](generate() ,dtype=float, count=-1) print(Z)31. 32. 33. 34. 35. 36. Create a vector of size 10 with values ranging from 0 to 1, both excluded (* * 7) Z = np. Linspace(0,1,12, endpoint=True) [1:-1] print(Z) Create a random vector of size 10 and sort it (* * 7) Z = np. random. random(10) [Link]() print(Z) How to sum a small array faster than [Link]? (* * ¥) # Author: Evgeni Burovski Z = [Link](10) [Link]. reduce (Z) Consider two random array A anb B, check if they are equal (* * vr) A = [Link](0,2,5) B = np. random. randint (0,2,5) equal = [Link](A,B) print (equal) Make an array immutable (read-only) (* * +) Z = [Link](10) [Link] = False Z{0] =1 Consider a random 10x2 matrix representing cartesian coordinates, convert them to polar coordinates (* #) np. random. random((10,2)) = 2[:,0], Z[:,1] np. sqrt (X**2#Y**2) np.arctan2(Y,X) print(R) print(T)37. Create random vector of size 10 and replace the maximum value by 0 (*«* 7) Z = np. random. random(10 2[[Link]()] = 0 print(Z) 38. Create a structured array with x and y coordinates covering the [0,1]x[0,1] area (ks) Z = [Link]((10,10), [('x', float), ('y', float)]) ZU'x'], Z['y'] = [Link]([Link](9,1,10), np. Linspace(0,1,10)) print(Z) 39. Given two arrays, X and Y, construct the Cauchy matrix C (Cij = 1/(xi - yj)) # Author: Evgeni Burovski X = [Link](8) X+0.5 C = 1.0 / [Link](X, Y) print (np. Linalg. det (C)) 40. Print the minimum and maximum representable value for each numpy scalar type (4S) for dtype in [np.int8, np.int32, np.int64]: print ([Link](dtype) .min) print ([Link](dtype) .max) for dtype in [np.float32, [Link]é4] print (np. finfo(dtype) .min) print (np. finfo(dtype) .max) print (np. finfo(dtype) .eps) 41, How to print all the values of an array? (* * x) np.set_printoptions(threshold=np. nan’ Z = [Link]((25,25)) print(Z)42. How to find the closest value (to a given scalar) in an array? (* * ¥) Z = [Link](100) v = [Link](0,100) index = ([Link](Z-v)).argmin() print (Z[index]) 43. Create a structured array representing a position (x,y) and a color (1,g,b) («* Z = [Link](10, [ ('position', [ ('x', float, 1), ('y', float, 1)1), (‘color', — [ (‘r', float, 1), (‘g', float, 1), ('b', float, 1)])]) print(Z) 44. Consider a random vector with shape (100,2) representing coordinates, find point by point distances (*« *s*°) Z = np. random. random((10,2)) X,Y = np.atleast_2d(Z[:,0]), np.atleast_2d(Z[:,1]) D = [Link]( (X-X.T)**2 + (Y-Y.T)**2) print(D) # Much faster with scipy import scipy # Thanks Gavin Heverly-Coulson (#issue 1) import [Link] np. random. random( (10,2) ) Zs D = scipy. spatial. distance. cdist(Z,Z) print(D) 45. How to convert a float (32 bits) array into an integer (32 bits) in place? [Link](10, dtype=np. int32) [Link](np.float32, copy=False) 46. How to read the following file? (* * sx) # File content: 6,,,7,8 219,10,11Z = [Link]("[Link]", delimiter=",") 47. What is the equivalent of enumerate for numpy arrays? (*« * x) Z = [Link](9) . reshape(3,3) for index, value in [Link](Z): print(index, value) for index in [Link]([Link]) : print(index, Z[index]) 48. Generate a generic 2D Gaussian-like array (* *¥) X, Y = [Link]([Link](-1,1,10), [Link](-1,1,10)) D = [Link] (X*X+Y*Y) sigma, mu = 1.0, 0.0 G = [Link](-( (D-mu)**2 / ( 2.0 * sigma**2 ) ) ) print(G) 49. How to randomly place p elements in a 2D array? (* * x) # Author: Divakar n= 10 p=3 Z = [Link]((n,n)) [Link](Z, [Link](range(n*n), p, replace=False) ,1) 50. Subtract the mean of each row of a matrix (* * vr) # Author: Warren Weckesser X = [Link](5, 10) Recent versions of numpy =X - [Link](axis=1, keepdims=True) <% Older versions of numpy = X - [Link](axis=1).reshape(-1, 1) <4
You might also like
100 Numpy Exercises Collection
PDF
No ratings yet
100 Numpy Exercises Collection
18 pages
Python Interview Cheat Sheet for Analysts
PDF
No ratings yet
Python Interview Cheat Sheet for Analysts
2 pages
NumPy Hyperbolic Functions Guide
PDF
No ratings yet
NumPy Hyperbolic Functions Guide
8 pages
NumPy Basics for AI and ML
PDF
No ratings yet
NumPy Basics for AI and ML
135 pages
Python Data Analysis with Pandas Guide
PDF
No ratings yet
Python Data Analysis with Pandas Guide
82 pages
Python Interview Questions
PDF
No ratings yet
Python Interview Questions
61 pages
Pandas and Numpy Exercises Guide
PDF
No ratings yet
Pandas and Numpy Exercises Guide
2 pages
R Basics for Data Analysis
PDF
No ratings yet
R Basics for Data Analysis
5 pages
NumPy: A Python Library Guide
PDF
No ratings yet
NumPy: A Python Library Guide
30 pages
Python Data Analysis with NumPy & Pandas
PDF
No ratings yet
Python Data Analysis with NumPy & Pandas
18 pages
Python 3 Sequence Containers Guide
PDF
No ratings yet
Python 3 Sequence Containers Guide
2 pages
Python List Comprehension Guide
PDF
No ratings yet
Python List Comprehension Guide
14 pages
Introduction to R Programming
PDF
100% (1)
Introduction to R Programming
189 pages
Python Programming for Data Science I
PDF
No ratings yet
Python Programming for Data Science I
6 pages
Python Dictionary Key Usage Explained
PDF
No ratings yet
Python Dictionary Key Usage Explained
2 pages
Python Loops: For & While Explained
PDF
No ratings yet
Python Loops: For & While Explained
7 pages
Python Tools for Parallel Computing
PDF
No ratings yet
Python Tools for Parallel Computing
16 pages
Data Science Course Overview: Python
PDF
No ratings yet
Data Science Course Overview: Python
172 pages
Python Data Science Cheat Sheet
PDF
No ratings yet
Python Data Science Cheat Sheet
4 pages
Python DSA Cheat Sheet: 100 Tricks
PDF
No ratings yet
Python DSA Cheat Sheet: 100 Tricks
4 pages
Data Visualization Techniques in Python
PDF
No ratings yet
Data Visualization Techniques in Python
16 pages
Aiohttp Performance: 1 Million Requests
PDF
No ratings yet
Aiohttp Performance: 1 Million Requests
9 pages
Pandas
PDF
No ratings yet
Pandas
1,689 pages
Seaborn Figure Styling Techniques
PDF
No ratings yet
Seaborn Figure Styling Techniques
15 pages
NumPy Arrays and Vectorized Computation
PDF
No ratings yet
NumPy Arrays and Vectorized Computation
51 pages
Python Practical Assignment Overview
PDF
No ratings yet
Python Practical Assignment Overview
35 pages
Python Patterns and Functions Guide
PDF
No ratings yet
Python Patterns and Functions Guide
16 pages
Seaborn: Advanced Statistical Plots
PDF
No ratings yet
Seaborn: Advanced Statistical Plots
10 pages
NumPy 2.0 Reference Guide
PDF
No ratings yet
NumPy 2.0 Reference Guide
1,128 pages
Manipulating and Analyzing Data With Pandas
PDF
No ratings yet
Manipulating and Analyzing Data With Pandas
50 pages
K-means Clustering Overview
PDF
No ratings yet
K-means Clustering Overview
13 pages
1.introduction To Python For Data Science
PDF
No ratings yet
1.introduction To Python For Data Science
6 pages
IPython Interactive Computing Cookbook
PDF
No ratings yet
IPython Interactive Computing Cookbook
43 pages
Python Programming Cheat Sheet
PDF
No ratings yet
Python Programming Cheat Sheet
5 pages
Python Assignments at Universal College
PDF
33% (3)
Python Assignments at Universal College
53 pages
Numpy Cheat Sheet & Quick Reference
PDF
No ratings yet
Numpy Cheat Sheet & Quick Reference
5 pages
Advanced Python for Scientific Computing
PDF
No ratings yet
Advanced Python for Scientific Computing
46 pages
C++ to Python Syntax Guide
PDF
No ratings yet
C++ to Python Syntax Guide
4 pages
Customer Segmentation with Python
PDF
No ratings yet
Customer Segmentation with Python
35 pages
Python Syntax Errors and Features
PDF
No ratings yet
Python Syntax Errors and Features
53 pages
Walter Oliveira Author Python For Advanced Developers Master Python With A Professional Approach
PDF
No ratings yet
Walter Oliveira Author Python For Advanced Developers Master Python With A Professional Approach
653 pages
Python Libraries in Data Science Analysis
PDF
No ratings yet
Python Libraries in Data Science Analysis
35 pages
Scikit-learn: A Comprehensive Overview
PDF
No ratings yet
Scikit-learn: A Comprehensive Overview
10 pages
Python Certification Course with Job Support
PDF
No ratings yet
Python Certification Course with Job Support
27 pages
Multi-variable Calculus & Linear Algebra
PDF
No ratings yet
Multi-variable Calculus & Linear Algebra
52 pages
Introduction to Pandas Data Structures
PDF
No ratings yet
Introduction to Pandas Data Structures
87 pages
Python Data Visualization Interview Guide
PDF
No ratings yet
Python Data Visualization Interview Guide
8 pages
Machine Learning Class Setup Guide
PDF
No ratings yet
Machine Learning Class Setup Guide
10 pages
Best Python Cheat Sheets for Beginners
PDF
100% (1)
Best Python Cheat Sheets for Beginners
17 pages
Tuples: Python For Everybody
PDF
No ratings yet
Tuples: Python For Everybody
16 pages
Comprehensive Data Science Cheat Sheets
PDF
No ratings yet
Comprehensive Data Science Cheat Sheets
18 pages
Neural Networks Implementation in Python
PDF
No ratings yet
Neural Networks Implementation in Python
8 pages
Python Basics Cheat Sheet for Data Science
PDF
100% (1)
Python Basics Cheat Sheet for Data Science
8 pages
500 Python Practice Questions Guide
PDF
No ratings yet
500 Python Practice Questions Guide
487 pages
Data Analysis Skills with Python Report
PDF
No ratings yet
Data Analysis Skills with Python Report
13 pages
Computer Science Sample Question Paper
PDF
No ratings yet
Computer Science Sample Question Paper
21 pages
100 Numpy Exercises for Practice
PDF
No ratings yet
100 Numpy Exercises for Practice
13 pages
Python Mock Question Bank
PDF
No ratings yet
Python Mock Question Bank
19 pages
100 Numpy Exercises for Beginners
PDF
No ratings yet
100 Numpy Exercises for Beginners
14 pages