<jupyter_start><jupyter_text>Create rank 1 & 2 arrays<jupyter_code>import numpy as np<jupyter_output><empty_output><jupyter_text>- First Way (Creating the array from a list)<jupyter_code>list1 = [1, 2, 3, 4]
list2 = [5, 6, 7, 8]

array1 = np.array(list1)
array2 = np.array(list2)

print(array1, array2)
big_list = [list1, list2] # [[1, 2, 3, 4], [5, 6, 7, 8]]

array = np.array(big_list)
print(array, "Array dimensions: {}".format(array.shape), sep="\n\n")<jupyter_output>[[1 2 3 4]
 [5 6 7 8]]

Longitud del array (2, 4)<jupyter_text>- Second Way (Creating the array directly)<jupyter_code>a = np.array([1, 2, 3]) #1 dimensional array or rank 1 array
a[0] = 5

print("Type of the array: {}".format(type(a)), "Array dimensions: {}".format(a.shape), sep="\n")
b = np.array([[1,2,3], [4,5,6]]) # Create a rank 2 array
print(b.shape)
print(b[0,0], b[0,1], b[1,0], sep=", ")<jupyter_output>(2, 3)
1, 2, 4<jupyter_text>Slicing arrays<jupyter_code>arr = np.array([[1,2,3,4], [5,6,7,8]])

arr1 = arr[0][:2]
arr2 = arr[1][1::2]
print(arr1, arr2)<jupyter_output>[1 2] [6 8]<jupyter_text>Keep in mind that if you do change in slice, it affects the parent array<jupyter_code>arr1[:] = 5
print(arr)
arr_new = np.array(([0,1,2],[3,4,5]))
print(arr_new[:2, 1:3])<jupyter_output>[[1 2]
 [4 5]]
{'fraction_non_alphanumeric': 0.2081377151799687, 'fraction_numerical': 0.07746478873239436, 'mean_word_length': 5.951086956521739, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '491614', 'license': 'Apache-2.0', 'n_tokens_mistral': 617, 'n_tokens_neox': 571, 'n_words': 141, 'path': 'Numpy/create-rank-1-2-arrays.ipynb', 'repo_name': 'aaronespasa/python-notebook', 'size': '1278'}