<jupyter_start><jupyter_text>Lists and Arrays<jupyter_code>import numpy as np

np.__version__
arr = np.array([
    [1, 2, 3],
    [4, 5, 6]
])

print("Array is of type: ", type(arr))

print("No of dimensions: ", arr.ndim)

print("Shape of array: ", arr.shape)

print("Size of array: ", arr.size)

print("Array stores elements of type: ", arr.dtype)
A = np.array([
    [1, 2, 4],
    [5, 8, 7]
], dtype = 'float')

print("\nArray created using passed list: \n", A)

B = np.array((1, 3, 2))
print("\nArray created using passed tuple: \n", B)

C = np.zeros(5)
print("\nArray initialized with all zeros: \n", C)

D = np.zeros([5, 5])
print("\n Array initialized with all zeros: \n", D)

E = np.ones([5, 5])
print("\n Array initialized with all ones: \n", E)

F = np.random.random([5, 5])
print("\n Array initialized with all randoms: \n", F)
A = np.array([1, 2, 3, 4])
print("\nAdding 1 to every element: ", A + 1)

print("\nSubtracking 3 from each element: ", A - 3)

print("\nMultiplying each element by 10: ", A * 10)

print("\nSquaring each element: ", A**2)

A *= 2
print("\nDoubled each element of original array: ", A)

B = np.array([
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9]
])
print("\nOriginal array: \n", B)
print("\nTranspose of array: \n", B.T)
A = np.array([
    [1, 2],
    [3, 4]
])

B = np.array([
    [5, 6],
    [7, 8]
])

print("\nVertical stacking:\n", np.vstack((A, B)))

print("\nHorizontal stacking:\n", np.hstack((A, B)))

C = [5, 6]
print("\nColumn stacking:\n", np.column_stack((A, C)))

print("\nConcatenating to 2nd axis:\n", np.concatenate((A, B), 1))<jupyter_output>Vertical stacking:
 [[1 2]
 [3 4]
 [5 6]
 [7 8]]

Horizontal stacking:
 [[1 2 5 6]
 [3 4 7 8]]

Column stacking:
 [[1 2 5]
 [3 4 6]]

Concatenating to 2nd axis:
 [[1 2 5 6]
 [3 4 7 8]]
{'fraction_non_alphanumeric': 0.20674157303370785, 'fraction_numerical': 0.04943820224719101, 'mean_word_length': 3.4193548387096775, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '101231', 'license': 'MIT', 'n_tokens_mistral': 792, 'n_tokens_neox': 721, 'n_words': 240, 'path': 'numpy/Ch1_Lists_and_Arrays.ipynb', 'repo_name': 'the-code-experiments/learning-numpy', 'size': '1780'}