<jupyter_start><jupyter_text>Basics<jupyter_code>a = np.array([1,2,3])
print(a)
a = np.array([[1,2,3,4],[5,6,7,8]])
print(a)
a
# dimensions
a.ndim
a.shape
# reshape
a.reshape((4,2))
a.reshape((2,2,2))
a.itemsize<jupyter_output><empty_output><jupyter_text>Accessing element in array<jupyter_code>a
# Get a specific element [r,c]
a[1,2]
# Get a specific row
a[0,:]
# Getting a little more fancy [startindex:endindex:stepsize]
a[0,1:3:2]
# Assign value 
a[0,2] = 10
a
# 3-d examples
b = np.array([[[1,2],[3,4]],[[5,6],[7,8]]])
b
# Get the specific value (works outside in)
b[1,0,0]<jupyter_output><empty_output><jupyter_text>Initializing Different Types of Arrays<jupyter_code># All zero's Matrix
np.zeros((3,3))
# All one's Matrix
np.ones((2,3))
# Any other number
np.full((3,3),9)
a
# Any other number (full_like)
np.full_like(a, 5)
# Random decimal numbers
np.random.rand(2,3)
# Random Interger values
np.random.randint(-4,8, size=(3,3))
# Indentity matrix
np.identity(3)
# Repeat an array
arr = np.array([[2,4,6]])
r1 = np.repeat(arr,3)
r1
r2 = np.repeat(arr,3,axis=0)
r2
# For copying arrays
b = a.copy()
b
b[0][1] = 9
a
b<jupyter_output><empty_output><jupyter_text>Mathematics<jupyter_code>a = np.array([1,2,3,4])
print(a)
a + 2
a - 2
a * 2
a / 2
b  = np.array([1,0,0,1])
a + b
a ** 2
np.cos(a)<jupyter_output><empty_output><jupyter_text>Statistics<jupyter_code>stats = np.array([[1,2,3],[4,5,6]])
stats
np.min(stats)
np.max(stats)
np.max(stats,axis=1)
np.sum(stats)
np.sum(stats,axis=0)<jupyter_output><empty_output><jupyter_text>Reshaping the array<jupyter_code>stats
stats.reshape((3,2))
stats.reshape((1,6))
# Vertically stacking vectors
v1 = np.array([1,2,3,4])
v2 = np.array([5,6,7,8])

np.vstack([v1,v2])
# Horizontal stack

np.hstack([v1,v2])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.19742007851934942, 'fraction_numerical': 0.05945036455412227, 'mean_word_length': 6.756521739130434, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '560379', 'license': 'MIT', 'n_tokens_mistral': 856, 'n_tokens_neox': 834, 'n_words': 148, 'path': 'Numpy Tutorial.ipynb', 'repo_name': 'SourabhSomdeve/Tutorials', 'size': '1783'}