<jupyter_start><jupyter_text>Getting started with Numpy Numpy is simply a Linear Algebra Library for Python. It is so important for Data Science with Python because almost all of the libraries in the PyData Ecosystem rely on NumPy as one of their main building blocks. Because of it bindings to C libraries, Numpy is incredibly fast. You might want to check out [StackOverflow post](http://stackoverflow.com/questions/993984/why-numpy-instead-of-python-lists) for more information on why you should use Arrays instead of lists.I will only show you the basics of Numpy starting from how to get it installed on your local machine!  Installing Numpy on your local machine  **It is highly recommended you install Python using the Anaconda distribution to make sure all underlying dependencies (such as Linear Algebra libraries) all sync up with the use of a conda install. If you already have Anaconda on your machine, you can  install Numpy by going to your terminal or command prompt and typing:**        conda install numpy    **If you don't already have Anaconda and can not install it, please visit [Numpy's official documentation on various installation instructions.](http://docs.scipy.org/doc/numpy-1.10.1/user/install.html)**  Using NumPyOnce you are able to install Numpy, you can import it as you would any other Python library:<jupyter_code>import numpy as np<jupyter_output><empty_output><jupyter_text>Numpy has many built-in functions and capabilities. We won't cover them all but instead we will focus on some of the most important aspects of Numpy: vectors,arrays,matrices, and number generation. Let's start by discussing arrays. Numpy ArraysNumpy arrays basically come in two forms: vectors and matrices. Vectors are strictly 1-d arrays while matrices are 2-d (but you should note a matrix can still have only one row or one column).We will begin our introduction by exploring how to create NumPy arrays. Creating NumPy Arrays From a Python ListA Numpy array can be created an array by directly converting a list or list of lists:<jupyter_code>my_list = [1,2,3,3,4,5]
my_list
np.array(my_list)
matrix = [[5,6,7],[8,9,10],[11,12,13]]
matrix
np.array(matrix)<jupyter_output><empty_output><jupyter_text>Built-in MethodsThere are lots of built-in methods to generate Arrays  arangeThis method return evenly spaced values within a given interval.<jupyter_code>np.arange(0,15)
np.arange(0,15,3)<jupyter_output><empty_output><jupyter_text>zeros and onesThis method generate arrays of zeros or ones<jupyter_code>np.zeros(5)
np.zeros((3,3))
np.ones(5)
np.ones((3,3))<jupyter_output><empty_output><jupyter_text>linspaceThis method return evenly spaced numbers over a specified interval.<jupyter_code>np.linspace(0,15,2)
np.linspace(0,15,25)<jupyter_output><empty_output><jupyter_text>eyeThis method creates an identity matrix<jupyter_code>np.eye(8)<jupyter_output><empty_output><jupyter_text>Random Numpy also provide lots of methods to create random number arrays: randThis create an array of the given shape and populate it withrandom samples from a uniform distributionover ``[0, 1)``.<jupyter_code>np.random.rand(5)
np.random.rand(3,3)<jupyter_output><empty_output><jupyter_text>randnThis return a sample from the "standard normal" distribution. Unlike rand which is uniform:<jupyter_code>np.random.randn(5)
np.random.randn(3,3)<jupyter_output><empty_output><jupyter_text>randintThis return random integers from `low` (inclusive) to `high` (exclusive).<jupyter_code>np.random.randint(1,50)
np.random.randint(1,50,5)<jupyter_output><empty_output><jupyter_text>Array Attributes and MethodsBelow are some useful attributes and methods or an array:<jupyter_code>array1 = np.arange(15)
array2 = np.random.randint(0,50,15)
array1
array2<jupyter_output><empty_output><jupyter_text>ReshapeThis method returns an array containing the same data with a new shape.<jupyter_code>array1.reshape(5,3)<jupyter_output><empty_output><jupyter_text>max,min,argmax,argminThese are useful methods for finding max or min values. Or to find their index locations using argmin or argmax<jupyter_code>array2
array2.max()
array2.argmax()
array2.min()
array2.argmin()<jupyter_output><empty_output><jupyter_text>ShapeShape is an attribute that arrays have (not a method):<jupyter_code># Vector
array1.shape
# Notice the two sets of brackets
array1.reshape(1,15)
array1.reshape(1,15).shape
array1.reshape(15,1)
array1.reshape(15,1).shape<jupyter_output><empty_output><jupyter_text>dtypeYou can also grab the data type of the object in the array:<jupyter_code>array1.dtype<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08211399868967023, 'fraction_numerical': 0.02314915920506661, 'mean_word_length': 6.633333333333334, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '14', 'dir': 'jupyter-structured-clean-dedup', 'id': '86820', 'license': 'MIT', 'n_tokens_mistral': 1472, 'n_tokens_neox': 1409, 'n_words': 494, 'path': 'Getting started with Numpy.ipynb', 'repo_name': 'ezekielolugbami/Getting-started-with-Numpy', 'size': '4579'}