<jupyter_start><jupyter_text>NumPy Broadcastinghttps://www.datacamp.com/community/tutorials/python-numpy-tutorialbroadcastinghttps://docs.scipy.org/doc/numpy/user/basics.broadcasting.html it’s a mechanism that allows NumPy to work with arrays of different shapes when you’re performing arithmetic operations.Broadcasting can be done if:- the dimensions of your arrays need to be compatible.  - when they are equal. - when one of them is 1  - if they are compatible in all dimensions. If these conditions are not met, a ValueError: operands could not be broadcast together exception is thrown<jupyter_code>import numpy as np
# when they are equal
x = np.ones((3,4))
print(x)
print(x.shape)
y = np.random.random((3,4))
print(y)
print(x.shape == y.shape)
x + y
# when one of them is 1 

# Initialize `x`
x = np.ones((3,4))

# Check shape of `x`
print(x.shape)

# Initialize `y`
y = np.arange(4)

# Check shape of `y`
print(y.shape)

# Subtract `x` and `y`
z = x - y 
print(z)
print(z.shape)
# if they are compatible in all dimensions.
# Initialize `x` and `y`
x = np.ones((3,4))
print(x.shape)
y = np.random.random((5,1,4))
print(y.shape)
# Add `x` and `y`
z = x + y
print(z.shape)<jupyter_output>(3, 4)
(5, 1, 4)
(5, 3, 4)
{'fraction_non_alphanumeric': 0.13442622950819672, 'fraction_numerical': 0.018032786885245903, 'mean_word_length': 4.308695652173913, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 2, 'lorem ipsum': 0, 'www.': 1, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '118767', 'license': 'MIT', 'n_tokens_mistral': 462, 'n_tokens_neox': 443, 'n_words': 150, 'path': 'day3/Numpy_Broadcasting.ipynb', 'repo_name': 'vsay01/My_AI_Challeges', 'size': '1220'}