<jupyter_start><jupyter_text><jupyter_code>#Practice on INTRO_NUMPY
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import numpy as np
arr = np.random.random((3, 2))  # Array of shape (3, 2), entries uniform in [0, 1).
print(arr)
# If we want to create an array with hard-coded values
ar = np.array([
    [0.0, 0.2],
    [0.9, 0.5],
    [0.3, 0.7],
], dtype=np.float64)  # float64 is the default.

print('The array is: \n', ar)
print()
print('data type: ', ar.dtype)
print('Shape is: ', ar.shape)
print('Transpose is: ', ar.T)
print('Array is reshaped:\n',ar.reshape(6))<jupyter_output>The array is: 
 [[0.  0.2]
 [0.9 0.5]
 [0.3 0.7]]

data type:  float64
Shape is:  (3, 2)
Transpose is:  [[0.  0.9 0.3]
 [0.2 0.5 0.7]]
Array is reshaped:
 [0.  0.2 0.9 0.5 0.3 0.7]<jupyter_text>Logical operators apply elementwise. Logical operators to have a boolean array<jupyter_code>ar_2 = np.array([   # Nearly the same as ar
    [0.0, 0.1],
    [0.9, 0.5],
    [0.0, 0.7],
])

# Where ar_2 is smaller than ar, let ar_2 be -inf.
ar_2[ar_2 < ar] = -np.inf
ar_2<jupyter_output><empty_output><jupyter_text>**Exercise**Broadcast and add the vector [10, 20, 30] across the columns of ar.You should getarray([[10. , 10.2],       [20.9, 20.5],       [30.3, 30.7]])<jupyter_code>vec = np.array([[10],[20],[30]])
#print(vec)
ar3 = ar + vec
print('original array:\n', ar)
print('array ar + vec:\n', ar3)<jupyter_output>original array:
 [[0.  0.2]
 [0.9 0.5]
 [0.3 0.7]]
**array ar + vec:**
 [[10.  10.2]
 [20.9 20.5]
 [30.3 30.7]]<jupyter_text>Exercise: Generate Data for NXORWrite a function get_data(num_examples) that returns two numpy arrays* inputs of shape ` num_examples` x 2 with points selected uniformly from the $[-1, 1]^2$ domain.* labels of shape `num_examples` with the associated output of NXOR.<jupyter_code>def get_data(num_examples):
  inputs = 2*np.random.random((num_examples,2)) - 1
  labels = np.prod(inputs, axis = 1)
  labels[labels <= 0] = -1
  labels[labels > 0] = 1
  return inputs, labels

get_data(4)<jupyter_output>
{'fraction_non_alphanumeric': 0.1657882127455678, 'fraction_numerical': 0.07187350263536177, 'mean_word_length': 3.878504672897196, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 15, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '365292', 'license': 'MIT', 'n_tokens_mistral': 917, 'n_tokens_neox': 846, 'n_words': 244, 'path': 'Untitled2.ipynb', 'repo_name': 'hazratali/PracticalSessions', 'size': '2087'}