<jupyter_start><jupyter_text>Logic functions<jupyter_code>import numpy as np
np.__version__<jupyter_output><empty_output><jupyter_text>Truth value testing Q1. Let x be an arbitrary array. Return True if none of the elements of x is zero. Remind that 0 evaluates to False in python.<jupyter_code>import numpy as np
x = np.array([1,2,3])
print np.all(x)

x = np.array([1,0,3])
print np.all(x)<jupyter_output>True
False<jupyter_text>Q2. Let x be an arbitrary array. Return True if any of the elements of x is non-zero.<jupyter_code>x = np.array([1,0,0])
print np.any(x)

x = np.array([0,0,0])
print np.any(x)<jupyter_output>True
False<jupyter_text>Array contents Q3. Predict the result of the following code.<jupyter_code>x = np.array([1, 0, np.nan, np.inf])
print np.isfinite(x)<jupyter_output>[ True  True False False]<jupyter_text>Q4. Predict the result of the following code.<jupyter_code>x = np.array([1, 0, np.nan, np.inf])
print np.isinf(x)<jupyter_output>[False False False  True]<jupyter_text>Q5. Predict the result of the following code.<jupyter_code>x = np.array([1, 0, np.nan, np.inf])
print np.isnan(x)<jupyter_output>[False False  True False]<jupyter_text>Array type testing Q6. Predict the result of the following code.<jupyter_code>x = np.array([1+1j, 1+0j, 4.5, 3, 2, 2j])
print np.iscomplex(x)<jupyter_output>[ True False False False False  True]<jupyter_text>Q7. Predict the result of the following code.<jupyter_code>x = np.array([1+1j, 1+0j, 4.5, 3, 2, 2j])
print np.isreal(x)<jupyter_output>[False  True  True  True  True False]<jupyter_text>Q8. Predict the result of the following code.<jupyter_code>print np.isscalar(3)
print np.isscalar([3])
print np.isscalar(True)<jupyter_output>True
False
True<jupyter_text>Logical operations Q9. Predict the result of the following code.<jupyter_code>print np.logical_and([True, False], [False, False])
print np.logical_or([True, False, True], [True, False, False])
print np.logical_xor([True, False, True], [True, False, False])
print np.logical_not([True, False, 0, 1])<jupyter_output>[False False]
[ True False  True]
[False False  True]
[False  True  True False]<jupyter_text>Comparison Q10. Predict the result of the following code.<jupyter_code>print np.allclose([3], [2.999999])
print np.array_equal([3], [2.999999])<jupyter_output>True
False<jupyter_text>Q11. Write numpy comparison functions such that they return the results as you see.<jupyter_code>x = np.array([4, 5])
y = np.array([2, 5])
print np.greater(x,y)
print np.greater_equal(x,y)
print np.less(x,y)
print np.less_equal(x,y)<jupyter_output>[ True False]
[ True  True]
[False False]
[False  True]<jupyter_text>Q12. Predict the result of the following code.<jupyter_code>print np.equal([1, 2], [1, 2.000001])
print np.isclose([1, 2], [1, 2.000001])<jupyter_output>[ True False]
[ True  True]
{'fraction_non_alphanumeric': 0.1362185172046825, 'fraction_numerical': 0.034054629301170626, 'mean_word_length': 6.085427135678392, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, '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': '13', 'dir': 'jupyter-structured-clean-dedup', 'id': '135172', 'license': 'MIT', 'n_tokens_mistral': 1149, 'n_tokens_neox': 1075, 'n_words': 291, 'path': 'Logic_functions.ipynb', 'repo_name': 'suryasuresh06/cvg1', 'size': '2819'}