<jupyter_start><jupyter_text>Creating Numpy Arrays<jupyter_code>!pip install numpy --upgrade
import numpy as np<jupyter_output><empty_output><jupyter_text>1. Create an array from a regular Python list or tuple using the array function<jupyter_code>array_one = np.array([1,2,3,4])
array_one
numbers = [9,8,7,6]
array_two = np.array(numbers)
array_two<jupyter_output><empty_output><jupyter_text>2. NumPy offers several functions to create arrays with initial placeholder contentCreate an array of zeros with desired shape (x,y)* x == number of rows* y == number of columns in array<jupyter_code>array_of_zeroes = np.zeros((3,4))
array_of_zeroes
array_of_ones = np.ones((3,4))
array_of_ones<jupyter_output><empty_output><jupyter_text>Use dtype in order to specify the data type<jupyter_code>array_of_ones_int = np.ones((3,4),dtype=np.int16)
array_of_ones_int<jupyter_output><empty_output><jupyter_text>np.empty() is not the same as np.zeros()One may get the same output. But np.empty() returns a new array of given shape and type, without initializing entries (the entries may be zero but not always)Used when you plan to populate the array but need to create one quickly first. If you want an array of zeros, use np.zeros()<jupyter_code>array_empty = np.empty((2,3))  
array_empty<jupyter_output><empty_output><jupyter_text>np.eye() creates an eyedentity matrix<jupyter_code>array_eye = np.eye(3)
array_eye<jupyter_output><empty_output><jupyter_text>3. To create sequences of numbers, NumPy provides a function analogous to range that returns arrays instead of lists arange(start, stop, step, dtype)<jupyter_code>array_of_evens = np.arange(2, 20, 2)
array_of_evens<jupyter_output><empty_output><jupyter_text>It also accepts float arguments<jupyter_code>array_of_floats = np.arange( 0, 2, 0.3)
array_of_floats<jupyter_output><empty_output><jupyter_text>Two Dimensional Arrays<jupyter_code>array_2d = np.array([(2,4,6),(3,5,7)]) 
array_2d
array_2d.shape<jupyter_output><empty_output><jupyter_text>Using reshape to create n dimensional arrays<jupyter_code>np.arange(6)
array_nd = np.arange(6).reshape(3,2) 
array_nd<jupyter_output><empty_output><jupyter_text>The reshape will only take arguments that multiply to the number in arange function.For example:for arange(8), the possible combinations for reshape are (2,4), (4,2), (2,2,2)<jupyter_code>array_nd = np.arange(6).reshape(3,4) 
array_nd
array_nd<jupyter_output><empty_output><jupyter_text>ones_like : Produce an array of all 1’s with the given shape and dtype. ones_like takes another array and produces a ones array of the same shape and dtype. There's also a zeros_like and empty_like<jupyter_code>array_ones = np.ones_like(array_nd)
array_ones<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09824046920821114, 'fraction_numerical': 0.020161290322580645, 'mean_word_length': 7.9183006535947715, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 49, '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': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '86906', 'license': 'MIT', 'n_tokens_mistral': 1001, 'n_tokens_neox': 968, 'n_words': 250, 'path': 'data/external/numpy-working-with-multidimensional-data/02/demos/m01_demo01_ArrayCreation.ipynb', 'repo_name': 'vickykatoch/pyTitanic', 'size': '2728'}