<jupyter_start><jupyter_text>Array Creation<jupyter_code>print('From a list or tuple: ')
d(np.array([1,2,3,4,5]))
print('1D array with zeros:')
d(np.zeros(10))
print('1D array with ones:')
d(np.ones(10))
print('2D array with ones on diagonal only:')
d(np.eye(2))
print('2D array with zeros integers:')
d(np.zeros((3,4), dtype=np.int))
print('1D array with a sequence:')
d(np.arange(1,10, 2))
print('1D array with evenly spaced sequence:')
d(np.linspace(1,10, 20))
print('1D array load from txt (csv format):')
d(np.genfromtxt('numpy-load-data.csv', delimiter=','))
print('1D array full of initial value:')
np.full(10, 23)
print('1D array with random values:')
np.random.random(10)

height_m = [1.80, 2.15, 2.10, 2.10, 1.88, 1.76, 2.09, 2.00]
weight_kg = [73, 88, 90, 65, 55, 67, 73, 91]

# Create a numpy array from baseball: np_baseball
np_height_m = np.array(height_m)
np_weight_kg = np.array(weight_kg)

print('Players height and weight:')
d(np_height_m, np_weight_kg)<jupyter_output>Players height and weight:<jupyter_text>NumPy array operatorsYou can use the usual math operators such as: `+`, `-`, `*`, `/`. Numpy will produce an new array by calculating element-wise with the given operator.<jupyter_code># Calculate the BMI: bmi
bmi = np_weight_kg / np_height_m ** 2

# Create the light array
light = bmi < 21

print('Lighter players:')
d(light)

print('BMIs of all baseball players whose BMI is below 21:')
d(bmi[light])<jupyter_output>Lighter players:<jupyter_text>**NOTE**: numpy arrays cannot contain elements with different types. If you try to build such a list, some of the elements' types are changed to end up with a homogeneous list. This is known as *type coercion*.Second, the typical arithmetic operators, such as +, -, * and / have a different meaning for regular Python lists and numpy arrays.  Subsetting NumPy arrays<jupyter_code>print('Weight for 5th player:')
d(np_weight_kg[4])

print('sub-array of np_height from 2nd to 5th players:')
d(np_height_m[1:4])<jupyter_output>Weight for 5th player:<jupyter_text>2D NumPy arrays<jupyter_code>players = [np_height_m, np_weight_kg]

# Create a 2D numpy array
np_players = np.transpose(np.array(players))

print('Players array shape:')
d(np_players.shape)

print('Players array:')
d(np_players)<jupyter_output>Players array shape:<jupyter_text>Subsetting 2D NumPy arrays<jupyter_code>print('The 5th player:')
d(np_players[4, :])

print('Select the entire second column (weight):')
d(np_players[:, 1])

print('Height of 2th player:')
d(np_players[1, 0])<jupyter_output>The 5th player:<jupyter_text>Basic statistics<jupyter_code>print('Player height mean:')
d(np_height_m.mean()) # Or from the players array: np.mean(np_players[:, 0])

print('Player height median:')
d(np.median(np_height_m))

print('Player mean on both height and weight:')
d(np_players.mean(axis=0))

print('Player height std:')
d(np_height_m.std())

print('Player max, min and sum height:')
d(np_height_m.max(), np_height_m.min(), np_height_m.sum())

print('Correlation between height and weight:')
print(np.corrcoef(np_players[:, 0], np_players[:, 1]))<jupyter_output>Player height mean:<jupyter_text>Reshape<jupyter_code>print('Reshape the height array to a 2D array (2x4):')
d(np_height_m.reshape((2,4)))

print('Transpose the players 2D array:')
d(np_players.transpose()) # Or np_players.T<jupyter_output>Reshape the height array to a 2D array (2x4):<jupyter_text>More operations<jupyter_code>print('Cumulative sum of the Player heights:')
d(np_height_m.cumsum())

print('Array copy:')
d(np_players.copy())

print('Switch data type:')
d(np_players.astype(np.int))<jupyter_output>Cumulative sum of the Player heights:
{'fraction_non_alphanumeric': 0.1432868471424665, 'fraction_numerical': 0.030352748154224774, 'mean_word_length': 6.766454352441613, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 25, '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': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '210613', 'license': 'MIT', 'n_tokens_mistral': 1447, 'n_tokens_neox': 1358, 'n_words': 368, 'path': 'notebooks/learning/numpy.ipynb', 'repo_name': 'fsquillace/notebooks', 'size': '3657'}