Intro To NumPy Arrays Flashcards
How to import NumPy
Import numpy as np
Converting a list to a numpy array
price_array = np.array(price)
quantity_sold_array = np.array(quantity_sold)
type(price_array
Output - numpy.ndarray
Adding to array
Price_array = price_array + [7]
print(price_array)
Output- [9 8 17]
To get original value back, we subtract 6, then use np.append() function to include the value 7 as desired
Price_array = price_array -[7]
Price_array = np.append(price_array, 7)
Print(price_array)
Output- [2 1 10 7]
To append multiple values to the array in one command
Price_array = np.append(price_array, [4.50, 3, 4, 9])
print(price_array)
Output- [2. 1. 10. 7. 4.5 3. 4. 9.]
To accommodate a value with decimal point and To check the data type of elements within the array
print(price.array.dtype)
Output- float64
To delete element in array
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.]
To replace element in array
Identify the index and use this function
price_array[2] = 12
print(price_array)
Output- [ 2. 1. 12. 7. 4.5 3. 4. ]
How to use enumerate function to slice out dinner options with its integer index
For I, food in enumerate(options_array):
print(fâ {i}: {food} â)