<jupyter_start><jupyter_text>Learning<jupyter_code>import numpy as np
L1 = [1,2,1000]
np.array(L1)
type(L1)
arr = np.array(L1)
type(arr)
my_mat = [[1,2],[3,4]]
type(my_mat)
my_mat = np.array(my_mat)
type(my_mat)
np.arange(30.)
list(range(0,30,1.5))
a = np.arange(1.5, 30., 1.4)
a.shape
a= a.reshape(21,1)
a.shape
a.T.shape
a+a
a = np.arange(1.5, 30., 1.4)
a+a
a*a
a/a
a = np.arange(30., 1.4)
a
a = np.arange(0,30,2)
ab = a/a
type(ab[0])
np.nan * 1
np.nan == np.nan
np.nan is np.nan
sum(ab)
arr = np.arange(1,10,0.1)
arr**2
np.sqrt(arr)
np.exp(arr)
np.max(arr)
np.sin(arr)
arr.dtype
np.array(range(10), dtype=np.float64).dtype
np.array(range(10)).dtype
np.array(range(10), dtype=complex)<jupyter_output><empty_output><jupyter_text>Nan<jupyter_code>a= None
type(a)
np.array([1,2,None, 50])
np.arange(1e6, dtype=np.int32)
%timeit np.arange(1e6, dtype='object').sum()
%timeit np.arange(1e6, dtype=np.int32).sum()<jupyter_output>2.69 ms ± 52.3 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)<jupyter_text>Making Numpy array<jupyter_code>import numpy as np
np.zeros((3,3))
np.ones((3,3))
np.empty((3,3))
x = np.array([[1,2,],[3,4]], dtype=complex)
x
np.zeros_like(x)
np.empty_like(x)
x= np.ones(4)
y = np.ones(4)*5
np.vstack((x,y))
np.hstack((x,y))
np.concatenate((x,y), axis=0)
x.shape
x = x.reshape(1,4)
y = y.reshape(1,4)
x.shape
np.linspace(0,100,500)<jupyter_output><empty_output><jupyter_text>Index<jupyter_code>arr = np.array([1,2,3,4])
arr
arr[-1]
arr[[True, False, True, True]]
arr != 2
arr[arr != 2]
arr[arr<=2]
arr = np.linspace(1,200)
arr[arr<50]
arr
np.random.randint(2,100,100)
import math
math.sin([0,1.4])
vsin = np.vectorize(math.sin)
vsin([0,1.4])
np.eye(2)
np.arange(100).reshape(20,-1)<jupyter_output><empty_output><jupyter_text>Logical Comparison<jupyter_code>v = np.array([1,2,3])
w = np.array([1,2,4])
v == w
if ((v==w).any()):
    print("They are equal")
else:
    print("They are not equal")
(v == w) & (v == w)
np.logical_and(v == w, v == w)
arr = np.random.rand(100,100)
np.savetxt("out.txt", arr)
np.loadtxt("out.txt")
np.save
import os
os.getcwd()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.2233285917496444, 'fraction_numerical': 0.07349454717875771, 'mean_word_length': 5.677215189873418, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 20, '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': '611716', 'license': 'MIT', 'n_tokens_mistral': 1118, 'n_tokens_neox': 1056, 'n_words': 181, 'path': 'notebooks/4 - Numpy.ipynb', 'repo_name': 'Gamein-SUT/DataMining-With-Python---Gamein2020', 'size': '2109'}