<jupyter_start><jupyter_text>Array Processing<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
points = np.arange(-5,5,0.01)
dx,dy = np.meshgrid(points,points)
dx
dy
z = (np.sin(dx) + np.sin(dy))
z
plt.imshow(z)
plt.imshow(z)
plt.colorbar()
plt.title('Plot for sin(x)+sin(y)')
# numpy where
A = np.array([1,2,3,4])
B = np.array([100,200,300,400])
condition = np.array([True, True, False, False])
answer = [(A_val if cond else B_val) for A_val, B_val, cond in zip(A,B,condition)]
answer
answer2 = np.where(condition,A,B) # basically this is a short form of the previous sentence
answer2
from numpy.random import randn
arr= randn(5,5)
arr
np.where(arr<0,0,arr) # cleaning up negative values
arr=np.array([[1,2,3],[4,5,6],[7,8,9]])
arr
arr.sum()
# adding it up along the 0th axis (columns) and 1st axis (rows)
for i in [0,1]:
    print('sum of axis', i, '=', arr.sum(i))
arr.mean()
arr.std()
arr.var()
bool_arr= np.array([True, False, True])
bool_arr.any() # returns true if anything is true
bool_arr.all() # returns true  if all are true
# sorting
arr=randn(5)
arr
arr.sort()
arr
countries = np.array(['France','Germany','USA','Russia','USA','Mexico','Germany'])
np.unique(countries) # unique values
np.in1d(['France','USA','Sweden'],countries) # to check if some values are in an array<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17433234421364985, 'fraction_numerical': 0.03115727002967359, 'mean_word_length': 5.88265306122449, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 5, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '380559', 'license': 'MIT', 'n_tokens_mistral': 549, 'n_tokens_neox': 520, 'n_words': 141, 'path': 'np/np4.ipynb', 'repo_name': 'subhamsarangi/Pdnp', 'size': '1348'}