Intro To NumPy Arrays Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

How to import NumPy

A

Import numpy as np

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Converting a list to a numpy array

A

price_array = np.array(price)
quantity_sold_array = np.array(quantity_sold)
type(price_array
Output - numpy.ndarray

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Adding to array

A

Price_array = price_array + [7]
print(price_array)
Output- [9 8 17]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

To get original value back, we subtract 6, then use np.append() function to include the value 7 as desired

A

Price_array = price_array -[7]
Price_array = np.append(price_array, 7)
Print(price_array)
Output- [2 1 10 7]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

To append multiple values to the array in one command

A

Price_array = np.append(price_array, [4.50, 3, 4, 9])
print(price_array)
Output- [2. 1. 10. 7. 4.5 3. 4. 9.]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

To accommodate a value with decimal point and To check the data type of elements within the array

A

print(price.array.dtype)

Output- float64

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

To delete element in array

A

We use indexing, we can use negative
price_array = np.delete(price_array, -1)
Print(price_array)
Output- [2. 1. 10. 7. 4.5 3. 4.]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

To replace element in array

A

Identify the index and use this function
price_array[2] = 12
print(price_array)
Output- [ 2. 1. 12. 7. 4.5 3. 4. ]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How to use enumerate function to slice out dinner options with its integer index

A

For I, food in enumerate(options_array):

print(f’ {i}: {food} ‘)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly