<jupyter_start><jupyter_text>HERE IS AN INTRODUCTION TO NUMPYSource Lecture: PIERAN DATAPARTICULARLY HOW TO CREATE NUMPY ARRAYS AND SOME BASIC ATTRIBUTES AND METHODS<jupyter_code># I begin by importing numpy as np which I will use to refernce throughout the notebook
import numpy as np<jupyter_output><empty_output><jupyter_text>How to Create a Numpy Array  1. From a Python ListWe can create an array by directly converting a list or list of lists using np.array(pass in a list/lol)<jupyter_code>myList = [1,2,3,4, 5]
myList
# Casting lists as arrays
np.array(myList)
myMatrix = [[1,2,3],[4,5,6],[7,8,9]]
myMatrix
#Casting a matrix as an array
np.array(myMatrix)<jupyter_output><empty_output><jupyter_text>2. By using Built-in Methods  A. arangeThis returns evenly spaced values within a given interval.<jupyter_code># np.arange(start-point, stop-point(excludig), step-size(optional))
np.arange(0,10)
np.arange(0,11,2)<jupyter_output><empty_output><jupyter_text>B. zeros and onesYou can generate arrays of zeros or ones<jupyter_code>np.zeros(6)
np.zeros((5,5))
np.ones(6)
np.ones((4,4))<jupyter_output><empty_output><jupyter_text>C. linspaceThis returns evenly spaced numbers over a specified interval.<jupyter_code>np.linspace(0,12,4)
np.linspace(0,10,50)<jupyter_output><empty_output><jupyter_text>D. eyeCreates an identity matrix<jupyter_code>np.eye(4)<jupyter_output><empty_output><jupyter_text>E. Random Numpy also has lots of ways to create random number arrays:  1. randThis creates an array of the given shape and populates it withrandom samples from a uniform distributionover ``[0, 1)``.<jupyter_code>np.random.rand(2)
np.random.rand(5,5)<jupyter_output><empty_output><jupyter_text>3. randnThis returns a sample (or samples) from the "standard normal" distribution. Unlike rand which is uniform:<jupyter_code>np.random.randn(3)
np.random.randn(6,6)<jupyter_output><empty_output><jupyter_text>4. randintThis returns random integers from `low` (inclusive) to `high` (exclusive).<jupyter_code>np.random.randint(1,100)
np.random.randint(1,100,10)<jupyter_output><empty_output><jupyter_text>Array Attributes and Methods<jupyter_code>arr = np.arange(25)
ranarr = np.random.randint(0,50,10)
arr
ranarr<jupyter_output><empty_output><jupyter_text>A. ReshapeReturns an array containing the same data with a new shape.<jupyter_code>arr.reshape(5,5)<jupyter_output><empty_output><jupyter_text>More...  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>ranarr
# Returns the maximum value from an Array
ranarr.max()
# Returns the argmax value from an Array
ranarr.argmax()
# Returns the minimum value from an Array
ranarr.min()
# Returns the argmin value from an Array
ranarr.argmin()<jupyter_output><empty_output><jupyter_text>B. ShapeShape is an attribute that arrays have (not a method):<jupyter_code># Vector
arr.shape
arr.reshape(1,25)
arr.reshape(1,25).shape
# make sure dimension match the array size
arr.reshape(5,5)
arr.reshape(25,1).shape<jupyter_output><empty_output><jupyter_text>dtypeYou can also grab the data type of the object in the array:<jupyter_code>arr.dtype<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10555902560899438, 'fraction_numerical': 0.024984384759525295, 'mean_word_length': 7.406824146981627, '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': '449558', 'license': 'MIT', 'n_tokens_mistral': 1194, 'n_tokens_neox': 1141, 'n_words': 299, 'path': 'Analysis_With_Numpy/1. Introduction to Numpy and NumPy Arrays.ipynb', 'repo_name': 'LavinaGeek/DataAnalysis', 'size': '3202'}