Skip to content

Commit ee74934

Browse files
committed
Scipy Numpy Lectures - Adding Finite & Infinite
Finite and Infinite Test element-wise for finiteness and infinity
1 parent b43c96b commit ee74934

File tree

1 file changed

+169
-3
lines changed

1 file changed

+169
-3
lines changed

numpy/SciPy Numpy Lecture 2 - Numerical operations on arrays.ipynb

+169-3
Original file line numberDiff line numberDiff line change
@@ -1411,9 +1411,9 @@
14111411
"cell_type": "markdown",
14121412
"metadata": {},
14131413
"source": [
1414-
"#### Had we done np.any() \n",
1414+
"#### If we would have done `np.any()`...\n",
14151415
"\n",
1416-
"What would the answer be then?"
1416+
"What would then the answer be then?"
14171417
]
14181418
},
14191419
{
@@ -1436,14 +1436,180 @@
14361436
"((a <= b) & (b <= c)).any()"
14371437
]
14381438
},
1439+
{
1440+
"cell_type": "markdown",
1441+
"metadata": {},
1442+
"source": [
1443+
"### Finite and Infinite\n",
1444+
"\n",
1445+
"Test element-wise for finiteness and infinity"
1446+
]
1447+
},
1448+
{
1449+
"cell_type": "code",
1450+
"execution_count": 79,
1451+
"metadata": {},
1452+
"outputs": [
1453+
{
1454+
"data": {
1455+
"text/plain": [
1456+
"True"
1457+
]
1458+
},
1459+
"execution_count": 79,
1460+
"metadata": {},
1461+
"output_type": "execute_result"
1462+
}
1463+
],
1464+
"source": [
1465+
"np.isfinite(1) # 1 is finite"
1466+
]
1467+
},
1468+
{
1469+
"cell_type": "code",
1470+
"execution_count": 88,
1471+
"metadata": {},
1472+
"outputs": [
1473+
{
1474+
"data": {
1475+
"text/plain": [
1476+
"True"
1477+
]
1478+
},
1479+
"execution_count": 88,
1480+
"metadata": {},
1481+
"output_type": "execute_result"
1482+
}
1483+
],
1484+
"source": [
1485+
"np.isfinite(np.exp(100))"
1486+
]
1487+
},
1488+
{
1489+
"cell_type": "code",
1490+
"execution_count": 89,
1491+
"metadata": {},
1492+
"outputs": [
1493+
{
1494+
"name": "stderr",
1495+
"output_type": "stream",
1496+
"text": [
1497+
"/Users/tarrysingh/anaconda/lib/python3.6/site-packages/ipykernel_launcher.py:1: RuntimeWarning: overflow encountered in exp\n",
1498+
" \"\"\"Entry point for launching an IPython kernel.\n"
1499+
]
1500+
},
1501+
{
1502+
"data": {
1503+
"text/plain": [
1504+
"False"
1505+
]
1506+
},
1507+
"execution_count": 89,
1508+
"metadata": {},
1509+
"output_type": "execute_result"
1510+
}
1511+
],
1512+
"source": [
1513+
"np.isfinite(np.exp(1000))"
1514+
]
1515+
},
1516+
{
1517+
"cell_type": "code",
1518+
"execution_count": 85,
1519+
"metadata": {},
1520+
"outputs": [
1521+
{
1522+
"name": "stderr",
1523+
"output_type": "stream",
1524+
"text": [
1525+
"/Users/tarrysingh/anaconda/lib/python3.6/site-packages/ipykernel_launcher.py:1: RuntimeWarning: overflow encountered in exp\n",
1526+
" \"\"\"Entry point for launching an IPython kernel.\n"
1527+
]
1528+
},
1529+
{
1530+
"data": {
1531+
"text/plain": [
1532+
"inf"
1533+
]
1534+
},
1535+
"execution_count": 85,
1536+
"metadata": {},
1537+
"output_type": "execute_result"
1538+
}
1539+
],
1540+
"source": [
1541+
"np.exp(1000)"
1542+
]
1543+
},
1544+
{
1545+
"cell_type": "markdown",
1546+
"metadata": {},
1547+
"source": [
1548+
"#### Above is a limitation of my computer...\n",
1549+
"\n",
1550+
"The answer should actually be true...\n",
1551+
"\n",
1552+
"...**but** if we do `np.isinf()'"
1553+
]
1554+
},
1555+
{
1556+
"cell_type": "code",
1557+
"execution_count": 90,
1558+
"metadata": {},
1559+
"outputs": [
1560+
{
1561+
"name": "stderr",
1562+
"output_type": "stream",
1563+
"text": [
1564+
"/Users/tarrysingh/anaconda/lib/python3.6/site-packages/ipykernel_launcher.py:1: RuntimeWarning: overflow encountered in exp\n",
1565+
" \"\"\"Entry point for launching an IPython kernel.\n"
1566+
]
1567+
},
1568+
{
1569+
"data": {
1570+
"text/plain": [
1571+
"True"
1572+
]
1573+
},
1574+
"execution_count": 90,
1575+
"metadata": {},
1576+
"output_type": "execute_result"
1577+
}
1578+
],
1579+
"source": [
1580+
"np.isinf(np.exp(1000))"
1581+
]
1582+
},
1583+
{
1584+
"cell_type": "code",
1585+
"execution_count": 91,
1586+
"metadata": {},
1587+
"outputs": [
1588+
{
1589+
"data": {
1590+
"text/plain": [
1591+
"False"
1592+
]
1593+
},
1594+
"execution_count": 91,
1595+
"metadata": {},
1596+
"output_type": "execute_result"
1597+
}
1598+
],
1599+
"source": [
1600+
"np.isfinite(np.inf) # Kind of obvious as infinity is definitely NOT finite"
1601+
]
1602+
},
14391603
{
14401604
"cell_type": "code",
14411605
"execution_count": null,
14421606
"metadata": {
14431607
"collapsed": true
14441608
},
14451609
"outputs": [],
1446-
"source": []
1610+
"source": [
1611+
"np.isfinite(np.log(-1.), 1., np.lo)"
1612+
]
14471613
}
14481614
],
14491615
"metadata": {

0 commit comments

Comments
 (0)