day 8. 1 Dimensional Arrays

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/3

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

4 Terms

1
New cards
import numpy as np

nums = [12, 4, 6, 7, 9, 21, 67, 8]
arr = np.array(nums)

print(arr)
arr.min()

the first line of code converts a list into a 1-D array with np.array(nums). The second line of code finds the lowest value of the array.

2
New cards

this is just a reference

import numpy as np

nums = [12, 4, 6, 7, 9, 21, 67, 8]
arr = np.array(nums)

print(arr)

describe this code

print(np.where(arr == arr.max()))

this code finds the indice of the highest value of the array with the np.where and max functions.

3
New cards

this is just a reference

import numpy as np

nums = [12, 4, 6, 7, 9, 21, 67, 8]
arr = np.array(nums)

print(arr)

describe this code

lowest_and_highest_values = np.array([arr.min(), arr.max()])

print(np.mean(lowest_and_highest_values))

np.array([arr.min(), arr.max()]) creates an array with the lowest and highest values of the original array. The mean of the lowest and highest values is calculated with the np.mean function.

4
New cards

this is just a reference

import numpy as np

nums = [12, 4, 6, 7, 9, 21, 67, 8]
arr = np.array(nums)

print(arr)

describe this code

import numpy as np 

q1 = np.percentile(arr, 25)
q3 = np.percentile(arr, 75)
iqr = q3 - q1
threshold = iqr * 1.5
outliers = np.where((arr < q1 - threshold) | (arr > q3 + threshold))

print(arr[outliers])

q1 = np.percentile(arr, 25) and q3 = np.percentile(arr, 75) calculates the 25th and 75th percentiles of the array. The interquartile range is calculated by subtracting the 75th percentile from the 25th percentile. The threshold is calculated by multiplying the interquartile range by 1.5. np.where((arr < q1 - threshold) | (arr > q3 + threshold)) calculates the outliers by finding values in the array that are less than the difference of the 25th percentile and threshold or greater than the sum of the 75th percentile and the threshold. The code is assigned to a variable called outliers which is indexed in the variable for the array to find its outliers.