<jupyter_start><jupyter_text>Numpy Exercise  1. Import the numpy package under the name  (★☆☆)<jupyter_code>import numpy as np<jupyter_output><empty_output><jupyter_text>2. Print the numpy version and the configuration  (★☆☆)<jupyter_code>print(np.__version__)
print(np.show_config())<jupyter_output>1.19.5
blas_mkl_info:
  NOT AVAILABLE
blis_info:
  NOT AVAILABLE
openblas_info:
    libraries = ['openblas', 'openblas']
    library_dirs = ['/usr/local/lib']
    language = c
    define_macros = [('HAVE_CBLAS', None)]
blas_opt_info:
    libraries = ['openblas', 'openblas']
    library_dirs = ['/usr/local/lib']
    language = c
    define_macros = [('HAVE_CBLAS', None)]
lapack_mkl_info:
  NOT AVAILABLE
openblas_lapack_info:
    libraries = ['openblas', 'openblas']
    library_dirs = ['/usr/local/lib']
    language = c
    define_macros = [('HAVE_CBLAS', None)]
lapack_opt_info:
    libraries = ['openblas', 'openblas']
    library_dirs = ['/usr/local/lib']
    language = c
    define_macros = [('HAVE_CBLAS', None)]
None<jupyter_text>3. Create a null vector of size 10 (★☆☆)<jupyter_code>arr = np.zeros(10)
print(arr)<jupyter_output>[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]<jupyter_text>4.  How to find the memory size of any array (★☆☆)<jupyter_code>a = arr.size
b = arr.itemsize
print("{} bytes".format(a*b))<jupyter_output>80 bytes<jupyter_text>5.  How to get the documentation of the numpy add function from the command line? (★☆☆)<jupyter_code>np.add?<jupyter_output><empty_output><jupyter_text>6.  Create a null vector of size 10 but the fifth value which is 1 (★☆☆)<jupyter_code>arr = np.zeros(10)
arr[4] = 1
print(arr)<jupyter_output>[0. 0. 0. 0. 1. 0. 0. 0. 0. 0.]<jupyter_text>7.  Create a vector with values ranging from 10 to 49 (★☆☆)<jupyter_code>arr = np.arange(10,50,5)
arr<jupyter_output><empty_output><jupyter_text>8.  Reverse a vector (first element becomes last) (★☆☆)<jupyter_code>np.flipud(arr)<jupyter_output><empty_output><jupyter_text>9.  Create a 3x3 matrix with values ranging from 0 to 8 (★☆☆)<jupyter_code>arr = np.random.randint(0,9,(3,3))
arr<jupyter_output><empty_output><jupyter_text>10. Find indices of non-zero elements from \[1,2,0,0,4,0\] (★☆☆)<jupyter_code>arr = np.array([1,2,0,0,4,0])
#ans = np.where(arr==0)
ans =  np.nonzero(arr)
ans<jupyter_output><empty_output><jupyter_text>11. Create a 3x3 identity matrix (★☆☆)<jupyter_code>np.eye(3,3)<jupyter_output><empty_output><jupyter_text>12. Create a 3x3x3 array with random values (★☆☆)<jupyter_code>np.random.random((3,3,3))<jupyter_output><empty_output><jupyter_text>13. Create a 10x10 array with random values and find the minimum and maximum values (★☆☆)<jupyter_code>arr = np.random.random((10,10))
a = np.max(arr)
b = np.min(arr)
print(a,b,sep="\n")<jupyter_output>0.9983346536039954
0.0017479738345612672<jupyter_text>14. Create a random vector of size 30 and find the mean value (★☆☆)<jupyter_code>arr = np.random.random((30))
ans = np.mean(arr)
ans<jupyter_output><empty_output><jupyter_text>15. Create a 2d array with 1 on the border and 0 inside (★☆☆)<jupyter_code>ans = np.ones((5,5))
ans[1:-1,1:-1] = 0
ans<jupyter_output><empty_output><jupyter_text>16. How to add a border (filled with 0's) around an existing array? (★☆☆)<jupyter_code>ans = np.ones((5,5))
np.pad(ans,pad_width = 1, mode = 'constant',constant_values = 0)<jupyter_output><empty_output><jupyter_text>17. What is the result of the following expression? (★☆☆) ```python0 * np.nannp.nan == np.nannp.inf > np.nannp.nan - np.nannp.nan in set([np.nan])0.3 == 3 * 0.1```<jupyter_code>print(0 * np.nan)
print(np.nan == np.nan)
print(np.inf > np.nan)
print(np.nan - np.nan)
print(np.nan in set([np.nan]))
print(0.3 == (3 * 0.1))<jupyter_output>nan
False
False
nan
True
False<jupyter_text>18. Create a 5x5 matrix with values 1,2,3,4 just below the diagonal (★☆☆)<jupyter_code>ans = np.diag([1,2,3,4],-1)
ans<jupyter_output><empty_output><jupyter_text>19. Create a 8x8 matrix and fill it with a checkerboard pattern (★☆☆)<jupyter_code>ans = np.zeros((8,8),dtype=int)
ans[1::2,::2] = 1
ans[::2,1::2] = 1
ans<jupyter_output><empty_output><jupyter_text>20. Consider a (6,7,8) shape array, what is the index (x,y,z) of the 100th element?<jupyter_code>np.unravel_index(99, (6,7,8))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16455399061032863, 'fraction_numerical': 0.05117370892018779, 'mean_word_length': 5.7958532695374805, 'pattern_counts': {'":': 0, '<': 75, '<?xml version=': 0, '>': 77, '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': '20', 'dir': 'jupyter-structured-clean-dedup', 'id': '198293', 'license': 'MIT', 'n_tokens_mistral': 1910, 'n_tokens_neox': 1819, 'n_words': 376, 'path': 'Numpy_Exercise.ipynb', 'repo_name': 'shawngeo/AI-Mafia---Machine-Learning', 'size': '4260'}