Legacy – Creating Arrays Workout
- 02:34
Workout demonstrating how to create a NumPy Array.
Glossary
Arrays NumPy LibraryTranscript
Suppose you would like to create an array of stock prices in Python, how would you do it, we will use the numpy package. Before doing anything, we need to import NumPy import NumPy as np, then, suppose we want to create an array of stock prices on Monday. So sp 500, underscore Monday equals n. To create an array, we need to use np dot array. Because we are using the numpy package to create the array, we need to mention the numpy package and take the array function from the package or the library. So the three values can be stock prices .4 and 137.6. And we run this. And because it's the first time we're running this file, we need to run it from here Ctrl, Shift f10. Then we print sp. Oh error, we forgot the bracket. There you go. That's theory, it looks like a list. Now in case we want to create an array of stock prices of Monday and Tuesday, and the data type is a float. How do we do that? It's simple. We say sp 500 say Tuesday equals it's np . array standard. And within the square brackets, we will have the two different values in a round bracket. So say the first one which has the Mondays values goes in this bracket. And then we separate it from the Tuesdays value using a comma and again the values goes in the brackets. So now we run this perfect, no errors returned. So we can print this array sp and we run this perfect. So that's how our array is defined. In case we want to mention that our array is a floating value meaning the data contains floats. We say d type equals a float, simple perfect