<jupyter_start><jupyter_text>NumPy Refresher  Load NumPy and check version<jupyter_code>import numpy as np
np.__version__<jupyter_output><empty_output><jupyter_text>NumPy is a huge library geared toward scientific computing -- most known for it's true array container<jupyter_code>x = np.arange(10)
print(x)
type(x)<jupyter_output>[0 1 2 3 4 5 6 7 8 9]<jupyter_text>Typically, computationally faster than working with Python Lists<jupyter_code>y = np.arange(1000000)
y = y ** 2
z = list(range(1000000))
z = z ** 2<jupyter_output><empty_output><jupyter_text>Data must be all of the same type - NumPy will attempt to coerce data<jupyter_code>animal = ['Dog', 'Mammal', 45, 7]
print(animal)
np.array(animal)<jupyter_output><empty_output><jupyter_text>Arrays can be "n"-dimensional --but most commonly one, two or three dimensional<jupyter_code>ndim = np.arange(27).reshape(3,3,3)
print(ndim)
twos = np.arange(16).reshape(2,2,2,2)
print(twos)<jupyter_output>[[[[ 0  1]
   [ 2  3]]

  [[ 4  5]
   [ 6  7]]]


 [[[ 8  9]
   [10 11]]

  [[12 13]
   [14 15]]]]<jupyter_text>Sometimes it's easier to define a data holder before actually the getting or generating the data<jupyter_code>print(np.ones((3,5)), end='\n\n')
print(np.zeros((3,5)), end='\n\n')
print(np.eye(3,5))<jupyter_output>[[1. 1. 1. 1. 1.]
 [1. 1. 1. 1. 1.]
 [1. 1. 1. 1. 1.]]

[[0. 0. 0. 0. 0.]
 [0. 0. 0. 0. 0.]
 [0. 0. 0. 0. 0.]]

[[1. 0. 0. 0. 0.]
 [0. 1. 0. 0. 0.]
 [0. 0. 1. 0. 0.]]<jupyter_text>Subsetting can be on one or more dimensions<jupyter_code>data = np.random.randint(10, size=15)
print(data)
data[4:8]
data = data.reshape(3,5)
data
data[0,0]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17082066869300913, 'fraction_numerical': 0.07598784194528875, 'mean_word_length': 4.39672131147541, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '122704', 'license': 'MIT', 'n_tokens_mistral': 796, 'n_tokens_neox': 697, 'n_words': 183, 'path': 'Section 1/1.2_NumPy_Refresher.ipynb', 'repo_name': 'PacktPublishing/Pandas-and-NumPy-Tips-Trick-and-Techniques', 'size': '1645'}