2020-04-21 12:42:19 -04:00
|
|
|
---
|
|
|
|
id: 5e9a0a8e09c5df3cc3600eda
|
|
|
|
title: Loading Data and Advanced Indexing
|
|
|
|
challengeType: 11
|
|
|
|
videoId: tUdBZ7pF8Jg
|
2021-01-13 03:31:00 +01:00
|
|
|
dashedName: loading-data-and-advanced-indexing
|
2020-04-21 12:42:19 -04:00
|
|
|
---
|
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
# --question--
|
2020-08-04 20:56:41 +01:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
## --text--
|
2020-04-21 12:42:19 -04:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
Given a file named `data.txt` with these contents:
|
2020-08-04 20:56:41 +01:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
```
|
|
|
|
29,97,32,100,45
|
|
|
|
15,88,5,75,22
|
|
|
|
```
|
2020-04-21 12:42:19 -04:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
What code would produce the following array?
|
2020-05-28 22:40:36 +09:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
```py
|
|
|
|
[29. 32. 45. 15. 5. 22.]
|
|
|
|
```
|
2020-05-28 22:40:36 +09:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
## --answers--
|
2020-05-28 22:40:36 +09:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
```py
|
|
|
|
filedata = np.genfromtxt('data.txt', delimiter=',')
|
|
|
|
output = np.any(filedata < 50)
|
2020-06-23 17:36:39 +05:30
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
print(output)
|
|
|
|
```
|
2020-05-28 22:40:36 +09:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
---
|
|
|
|
|
|
|
|
```py
|
|
|
|
filedata = np.genfromtxt('data.txt', delimiter=',')
|
|
|
|
output = np.all(filedata < 50, axis=1)
|
|
|
|
|
|
|
|
print(output)
|
|
|
|
```
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
```py
|
|
|
|
filedata = np.genfromtxt('data.txt', delimiter=',')
|
|
|
|
output = filedata[filedata < 50]
|
|
|
|
|
|
|
|
print(output)
|
|
|
|
```
|
2020-05-28 22:40:36 +09:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
## --video-solution--
|
2020-05-28 22:40:36 +09:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
3
|
2020-04-21 12:42:19 -04:00
|
|
|
|