<jupyter_start><jupyter_text>Creating Arrays<jupyter_code>a = np.array([1,2,3,4])
print(a)
a.ndim  # 1 dimensional array
a.shape
b = a.reshape(4,1)
print(b)
b.ndim  # 2 dimensional array

len(b)
c = np.array([[1,2,3],[4,5,6]])
print(c)
c.reshape(3,2)

c.T
# 3 dimensional array

d = np.array([[[1,2,3],[4,5,6]],[[7,8,9],[1,5,9]]])
print(d)
d.ndim
d[1:,1:]  # 2nd dimension 2 row
np.linspace(1,10,5)
np.ones(3)
np.ones([2,2])
np.zeros([1,2])
np.eye(3)
a = np.eye(4,3)
print(a)
a = np.diag([1,2,3])
print(a)
print(np.random.rand(2,5))  # uniform variate 0 to 1
print(np.random.randn(2,5)) # normal standard variate mean = 0 and std = 1
print(np.random.randint(2,50,5))
a = np.arange(10)
a[5:7]
a = np.diag([1,2,3])
a[1,1]
a[2,1] = 5
a<jupyter_output><empty_output><jupyter_text>Slicing<jupyter_code>b = np.arange(0,20,2)
b  = b[b<11]
b
a = np.arange(10)
print(a)
a[4:] = b[::-1] 
a<jupyter_output><empty_output><jupyter_text>Copy and view<jupyter_code>a = np.arange(10)
print(a)
b = a[::2]
b
np.shares_memory(a,b)
b[0] = 10
b
a<jupyter_output><empty_output><jupyter_text>above when i change b[0] variable a itself changed<jupyter_code>c = a[::2].copy()
c
c[0]=10
c
# here variable a wont change since i used copy()
a
np.shares_memory(a,c)<jupyter_output><empty_output><jupyter_text>Masking<jupyter_code>a = np.random.randint(0,20,15)
a
mask = (a%2==0)
b
extract_from_a = a[mask]
extract_from_a
a[mask] = -1
a
# Indexing with an array of integers

a = np.arange(0,100,10)
a
a[[2,3,3,2,4]]
a[[9,7]] = 100
a<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.20887728459530025, 'fraction_numerical': 0.07637075718015666, 'mean_word_length': 6.032110091743119, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 21, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '551509', 'license': 'MIT', 'n_tokens_mistral': 820, 'n_tokens_neox': 781, 'n_words': 139, 'path': 'Data visualization/Numpy by AAIC.ipynb', 'repo_name': 'krish1511/Python', 'size': '1532'}