<jupyter_start><jupyter_text>4. Creating NumPy ArraysUnderstand the different ways in which Arrays can be created - 1D and 2D1. `array()` - Create numpy array from List, tuples and dictionaries2. `ones()` - Create an array of 1s.3. `zeros()` - Create an array of 0s.4. `arange()` - Create an array with the continuous integers.5. `linspace()` - Generate values which are equally spaced from each other.6. `random.random()` - Create array of random numbers  1. Create Array using `array()`   1.1. Create array from List<jupyter_code>import numpy as np

player_heights = [1.5, 1.7, 1.55, 1.68, 1.99, 1.87, 2.1, 1.45, 1.99, 1.83]

# Create from a List
np_player_heights = np.array(player_heights)
np_player_heights
# Create from a list
np_arr = np.array([111, 102, 145, 156])
np_arr<jupyter_output><empty_output><jupyter_text>1.2. Create array from Tuples<jupyter_code># Create from a Tuples
currencies = ("Dollars", "Rupees", "Pounds", "Euros")
currencies_arr = np.array(currencies)
currencies_arr<jupyter_output><empty_output><jupyter_text>1.3. Create array from Dictionaries - dict.items()<jupyter_code># Create from a Dictionary
currencies_dict = {"Dollars": "$", "Rupees": "₹", "Pounds": "£", "Euros": "€"}
print(currencies_dict.items())

currencies_2d_arr = np.array(list(currencies_dict.items()))
currencies_2d_arr
currencies_2d_arr.dtype
currencies_2d_arr.shape
currencies_2d_arr.ndim<jupyter_output><empty_output><jupyter_text>2. Create using `ones()`<jupyter_code>arr_ones = np.ones(10)
arr_ones
arr_ones = np.ones(10, dtype=int)
arr_ones
arr_ones.ndim
arr_ones.size
arr_ones.shape<jupyter_output><empty_output><jupyter_text>2.2. Introduction to reshape(m,n)<jupyter_code>ones_2d_arr = arr_ones.reshape(2,5)
ones_2d_arr
ones_2d_arr = arr_ones.reshape(2,6)
ones_2d_arr
ones_2d_arr.shape
ones_2d_arr.size
type(ones_2d_arr)
ones_2d_arr.itemsize
ones_2d_arr = arr_ones.reshape(2,5).astype('int32')
ones_2d_arr.itemsize<jupyter_output><empty_output><jupyter_text>3. Create using `zeros()`  Simple 1xD Array with Zeros<jupyter_code>zeros_arr = np.zeros(20)
zeros_arr
zeros_arr.ndim<jupyter_output><empty_output><jupyter_text>Simple, int type 2xD array with Zeros<jupyter_code>zeros_arr = np.zeros(dtype=int, shape=(4,5))
zeros_arr
zeros_arr.ndim<jupyter_output><empty_output><jupyter_text>4. Create array using `arange()` 4.1. Simple 1xD Array<jupyter_code>np.arange(11)
np.arange(1,50,5)<jupyter_output><empty_output><jupyter_text>4.2. Simple 2xD Array<jupyter_code>np.arange(15).reshape(5,3)<jupyter_output><empty_output><jupyter_text>5. Create array using `linspace()`Array of length 30 between 1 and 500<jupyter_code>np.linspace(1,500,30)
np.linspace(1,500,30).reshape(5,6)<jupyter_output><empty_output><jupyter_text>6. Create array of random numbers - `np.random.random()`Return random floats in the half-open interval [0.0, 1.0). Alias for random_sample to ease forward-porting to the new random API.  5.1. Generate a random number<jupyter_code>np.random.random()<jupyter_output><empty_output><jupyter_text>5.2. Generate an [m, n] array filled with random floats<jupyter_code>np.random.random([5,4])<jupyter_output><empty_output><jupyter_text>5.3. [m, n] array filled with random floats between 0 to 100<jupyter_code>np.random.random([5,4])*100<jupyter_output><empty_output><jupyter_text>5.3. Generate an [m, n] array filled with random integers - 0 to 12<jupyter_code>np_int32_rarray = (np.random.random([4,5])*12).astype('int32')
np_int32_rarray<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1323191733639495, 'fraction_numerical': 0.048507462686567165, 'mean_word_length': 7.238770685579196, 'pattern_counts': {'":': 4, '<': 57, '<?xml version=': 0, '>': 57, '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': '14', 'dir': 'jupyter-structured-clean-dedup', 'id': '350452', 'license': 'MIT', 'n_tokens_mistral': 1478, 'n_tokens_neox': 1375, 'n_words': 278, 'path': 'NumPy/04. Creating NumPy Arrays.ipynb', 'repo_name': 'jstobigdata/Master-the-Data-Science', 'size': '3484'}