<jupyter_start><jupyter_text>PolynomialsNumPy also contains polynomials in different bases:For example, 3x^2 + 2x - 1<jupyter_code>import numpy as np

p = np.poly1d([3, 2, -1])
p[0]
p.roots
p.order
x = np.linspace(0, 1, 20)
x
y = np.cos(x) + 0.3*np.random.rand(20)
y
p = np.poly1d(np.polyfit(x, y, 3))
p
t = np.linspace(0, 1, 200)

import matplotlib.pyplot as plt
%matplotlib inline

plt.plot(x, y, 'o', t, p(t), '-')<jupyter_output><empty_output><jupyter_text>More polynomials (with more bases)NumPy also has a more sophisticated polynomial interface, which supports e.g. the Chebyshev basis.3x^2 + 2x - 1:<jupyter_code>p = np.polynomial.Polynomial([-1, 2, 3])
p
p(0)
p.roots()
p.degree()<jupyter_output><empty_output><jupyter_text>**Example using polynomials in Chebyshev basis, for polynomials in range [-1, 1]:**<jupyter_code>x = np.linspace(-1, 1, 2000)
y = np.cos(x) + 0.3*np.random.rand(2000)

p = np.polynomial.Chebyshev.fit(x, y, 90)

t = np.linspace(-1, 1, 200)

plt.plot(x, y, 'r')
plt.plot(t, p(t), 'k-', lw=3)
plt.plot(x, y, 'r')
plt.plot(t, p(t), 'k-', lw=3)<jupyter_output><empty_output><jupyter_text>The Chebyshev polynomials have some advantages in interpolation.  Loading data files  Text files<jupyter_code>data = np.loadtxt('data/populations.txt')
data
np.savetxt('data/pop2.txt', data)
data2 = np.loadtxt('data/pop2.txt')
data2
pwd
cd data
ls<jupyter_output>Volume in drive C is PRIME
 Volume Serial Number is 948E-1F83

 Directory of C:\Users\Sourav\For_GitHub_Repos\DataScience_Python\Numpy\data

26-01-2018  04:20 PM    <DIR>          .
26-01-2018  04:20 PM    <DIR>          ..
26-01-2018  04:17 PM    <DIR>          .ipynb_checkpoints
26-01-2018  04:20 PM             2,100 pop2.txt
26-01-2018  04:17 PM               525 populations.txt
               2 File(s)          2,625 bytes
               3 Dir(s)  30,060,187,648 bytes free<jupyter_text>ImagesUsing Matplotlib:<jupyter_code>cd ..
img = plt.imread('data/elephant.png')
img.shape, img.dtype
plt.imshow(img)
plt.savefig('data/elephant_plot.png')
plt.imsave('data/gray_elephant.png', img[:,:,0], cmap=plt.cm.gray)
plt.imshow(plt.imread('data/gray_elephant.png'))

plt.imsave('data/tiny_elephant.png', img[::6,::6])
plt.imshow(plt.imread('data/tiny_elephant.png'), interpolation='nearest')<jupyter_output><empty_output><jupyter_text>**Exercise: Text data files** Write a Python script that loads data from populations.txt:: and drop the last column and the first 5 rows. Save the smaller dataset to pop3.txt.<jupyter_code>data
data3 = data.T
data3
data3 = data3[:-1]
data3
data3 = data3.T
data3
data3 = data3[5:]
data3
np.savetxt('data/pop3.txt', data3)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1523452157598499, 'fraction_numerical': 0.06378986866791744, 'mean_word_length': 4.332, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '199607', 'license': 'MIT', 'n_tokens_mistral': 1206, 'n_tokens_neox': 1079, 'n_words': 241, 'path': 'Numpy/Advanced_operations.ipynb', 'repo_name': 'SrGrace/DataScience_Jupyter_Notebook', 'size': '2665'}