<jupyter_start><jupyter_text>Accessing/Changing specific elements, rows, columns, etc<jupyter_code>import numpy as np
a = np.array([[1,2,3,4,5,6,7],[8,9,10,11,12,13,14]])
print(a)
a.shape
# Get a specific elelment [r, c]
a[1, 5]
# Get a specific elelment [r, c]
a[1, -2]
# Get a specific row
a[0, :]
# Get a specific column
a[:, 2]
# Getting a little more fancy [startindex:endindex:stepsize]
a[0, 1:6:2]
# Getting a little more fancy [startindex:endindex:stepsize]
a[0, 1:-1:2]
a[1,5] = 20
print(a)
a[1,5] = 20
print(a)

a[:,2] = 5
print(a)
a[1,5] = 20
print(a)

a[:,2] = [1,2]
print(a)<jupyter_output>[[ 1  2  5  4  5  6  7]
 [ 8  9  5 11 12 20 14]]
[[ 1  2  1  4  5  6  7]
 [ 8  9  2 11 12 20 14]]<jupyter_text>3-d example:<jupyter_code>b = np.array([[[1,2],[3,4]],[[5,6],[7,8]]])
print(b)
# Get specific element (work outside in)
b[0,1,1]
# Get specific element (work outside in)
b[:,0,:]
# replace (same dimension)
b[:,1,:] = [[9,9],[8,8]]
b<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.20799180327868852, 'fraction_numerical': 0.10655737704918032, 'mean_word_length': 4.747058823529412, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '535372', 'license': 'MIT', 'n_tokens_mistral': 507, 'n_tokens_neox': 469, 'n_words': 122, 'path': 'FreeCodeCamp/Data Analysis with Python/Numpy/3 - Accessing and Changing Elements, Rows, Columns.ipynb', 'repo_name': 'saulpaiva/Code', 'size': '976'}