<jupyter_start><jupyter_text>Learning objectives:* **How to create n-dimensional arrays using some placeholder functions:**1. np.array()2. np.zeros()3. np.empty()4. np.arange()5. np.linspace()* **How to convert the data type of a numpy array**<jupyter_code>!pip install numpy
## import the package

import numpy as np<jupyter_output><empty_output><jupyter_text>Creating NumPy arrays using `np.array()`<jupyter_code>price = [1200, 50, 12, 13.5, 200]

type(price)

price_arr = np.array(price)
price_arr
type(price_arr)
price_arr.dtype
arr2 = np.array([2,3,4,5,6])
print(arr2)
arr3 = np.array([2,3,4,5,'tom'])
arr3
arr3.dtype
type(arr3)
arr3.shape
arr3.ndim
arr_2d = np.array([
    [1,2,3],
    [4,5,6],
    [7,8,9]
])
arr_2d
arr_2d.ndim
arr_2d.shape
arr_2d.size
arr_3d = np.array([
    [[1,2], [3,4],
    [5,6], [7,8]]
]
)
arr_3d
arr_3d.ndim
arr_3d.shape
arr_3d[0]
arr_3d = np.array([
    [[1,2], [3,4],
    [5,6], [7,8]],
    [[1,2], [3,4],
    [5,6], [7,8]]
]
)
arr_3d.shape
arr_3d.size
arr_3d[1]
arr_3d[0]
arr_3d[0][2].shape
arr_3d[0][2][1]
arr_3d.shape<jupyter_output><empty_output><jupyter_text>np.zeros<jupyter_code>arr_1d = np.zeros(10)
arr_1d
arr2_0 = np.zeros((5,5))
arr2_0<jupyter_output><empty_output><jupyter_text>np.empty()<jupyter_code>arr2_empty = np.empty((2,3))
arr2_empty<jupyter_output><empty_output><jupyter_text>np.arange()<jupyter_code>range(1, 10, 1)
np.arange(1, 10, 1)
np.arange(10)
np.arange(1, 10, 2)
odd_num = np.arange(1, 100, 2)
odd_num<jupyter_output><empty_output><jupyter_text>np.linspace()<jupyter_code>np.linspace(1, 10, 100)
np.linspace(1, 100, 10)<jupyter_output><empty_output><jupyter_text>How to work with data types<jupyter_code>odd_num = np.arange(1, 100, 2, dtype=np.float64)
print(odd_num)
narr = np.array([1, 2.5, 3], dtype=np.int32)
narr
a = np.array([2,4,5.6, 6, 7])
a.dtype
a_int = a.astype(np.int32)
a_int<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18872939925571505, 'fraction_numerical': 0.08559276980329612, 'mean_word_length': 6.210727969348659, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '119954', 'license': 'MIT', 'n_tokens_mistral': 968, 'n_tokens_neox': 920, 'n_words': 146, 'path': 'module_3_numpy/intro_to_numpy_arrays.ipynb', 'repo_name': 'wiplane/foundations-of-datascience-ml', 'size': '1881'}