<jupyter_start><jupyter_text>1. Create a numpy array of size 10, filled with zeros<jupyter_code>np.zeros(10)<jupyter_output><empty_output><jupyter_text>2. Create a numpy array with values ranging from 10 to 49<jupyter_code>np.arange(10, 50)<jupyter_output><empty_output><jupyter_text>3. Create a numpy matrix of 2*2 integers, filled with ones<jupyter_code>np.ones([2, 2], dtype=int)<jupyter_output><empty_output><jupyter_text>4. Create a numpy matrix of 3*2 float numbers, filled with ones<jupyter_code>np.ones([3, 2], dtype=float)<jupyter_output><empty_output><jupyter_text>5. Given the X numpy array, create a new numpy array with the same shape and type as X, filled with ones<jupyter_code>x = np.array([[1, 2, 3],
            [4, 5, 6]])

y = np.ones(x.shape)
y<jupyter_output><empty_output><jupyter_text>6. Given the X numpy matrix, create a new numpy matrix with the same shape and type as X, filled with zeros<jupyter_code>np.zeros(x.shape, dtype=x.dtype)<jupyter_output><empty_output><jupyter_text>Create a numpy matrix of 4*4 integers, filled with fives<jupyter_code>np.ones(4)*5<jupyter_output><empty_output><jupyter_text>7. Create a 3*3 identity numpy matrix with ones on the diagonal and zeros elsewhere<jupyter_code>np.identity(3)<jupyter_output><empty_output><jupyter_text>8. Create a numpy array, filled with 3 random integer values between 1 and 10<jupyter_code>print(np.random.randint(1, 10, size=5))
print(np.random.choice([3, 4, 5, 6], size=(3, 4)))<jupyter_output>[7 1 8 6 9]
[[5 5 4 5]
 [3 5 5 6]
 [6 6 5 3]]<jupyter_text>9. Create a 3 * 3 * 3 numpy matrix, filled with random float values<jupyter_code>np.random.ranf(size=(3, 3, 3))<jupyter_output><empty_output><jupyter_text>10. Given the X python list conver it to an Y numpy array<jupyter_code>import sys
l = [1, 2, 3, 4, 5]
a = np.array(l)
a<jupyter_output><empty_output><jupyter_text>11. create the X numpy array, make a copy and store it on Y<jupyter_code>x
y = np.copy(x)
y<jupyter_output><empty_output><jupyter_text>12. Create a numpy array with numbers from 1 to 10<jupyter_code>np.arange(1, 11)<jupyter_output><empty_output><jupyter_text>13. Create a numpy array with numbers from 1 to 10, in descending order<jupyter_code>np.arange(start=10, stop=0, step=-1)<jupyter_output><empty_output><jupyter_text>14. Create a 3*3 numpy matrix, filled with values ranging from 0 to 8<jupyter_code>z = np.arange(9).reshape(3,3)
z<jupyter_output><empty_output><jupyter_text>15. Show the memory size of the given Z numpy matrix<jupyter_code>z.size*z.itemsize<jupyter_output><empty_output><jupyter_text>16. Given the X numpy array, show its first element<jupyter_code>z[0,0]<jupyter_output><empty_output><jupyter_text>17. Given the X numpy array, show its last element<jupyter_code>z[-1, -1]
z.size<jupyter_output><empty_output><jupyter_text>18. Given the X numpy array, show all middle elements<jupyter_code>p = np.full((3, 4), 0)
k=int(z.shape[0]/2)
z[k]<jupyter_output><empty_output><jupyter_text>19. Given the X numpy array, show the elements in reverse position<jupyter_code>li = []
for n in reversed(z):
    for i in reversed(n):
        li.append(i)
        
print(f'memory of the list: {sys.getsizeof(li)}')
k = np.array(li)
print(f'memory of the array {k} is: {k.size*k.itemsize}')<jupyter_output>memory of the list: 184
memory of the array [8 7 6 5 4 3 2 1 0] is: 72<jupyter_text>20. Given the X numpy array, show the elements in an odd position<jupyter_code>x = np.arange(10)
odd_list = np.arange(1, 10, 2)
print(x)
print(x[odd_list])<jupyter_output>[0 1 2 3 4 5 6 7 8 9]
[1 3 5 7 9]<jupyter_text>Array manipulation Convert the given integer numpy array to floar<jupyter_code>x = np.arange(10)
np.array(x, dtype=float)<jupyter_output><empty_output><jupyter_text>Reverse the given numpy array(first element becomes last)<jupyter_code>x = np.arange(10)
print(np.flip(x))
x = x[::-1]
x<jupyter_output>[9 8 7 6 5 4 3 2 1 0]<jupyter_text>sort the given numpy array<jupyter_code>x = np.random.randint(1, 10, 10)
x
np.sort(x)<jupyter_output><empty_output><jupyter_text>Given the X numpy array, set the fifth element equal to 1<jupyter_code>x = np.arange(0, 10)
x[4] = 1
x<jupyter_output><empty_output><jupyter_text>Given the x numpy array, get number equal to 2 or 10<jupyter_code>x[((x == 2) | (x == 10))]<jupyter_output><empty_output><jupyter_text>Given the x numpy array, return True if none of its elements is zero<jupyter_code>len(x[x==0])>0<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12412862604002699, 'fraction_numerical': 0.04587362266696649, 'mean_word_length': 6.450586264656616, 'pattern_counts': {'":': 0, '<': 105, '<?xml version=': 0, '>': 106, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '27', 'dir': 'jupyter-structured-clean-dedup', 'id': '637519', 'license': 'MIT', 'n_tokens_mistral': 1883, 'n_tokens_neox': 1726, 'n_words': 469, 'path': 'Numpy code snippets.ipynb', 'repo_name': 'barnwalp/jupyter_notebook', 'size': '4447'}