Hello everyone and welcome to the PI operations lecture and this lecture we're going to show you basic
operations reform on an umpire array's.
Let's go ahead and jump to the Jupiter notebook to get started.
All right so here we are at the Jupiter note book.
We'll go ahead and discuss array with array operations array with scalar operations and then some universal
array functions what they are and how you can find more of them will go ahead and start by saying important
pi as NPE.
And then I'm going to go ahead and make an array we'll say N.P. arrange and we'll just go ahead and
go from zero comma 11.
So that way we get digits 0 through 10 so 11 digits from 0 to 10.
All right.
You can easily perform array with array operations just by using simple arithmetic signs that you're
already used to from Python itself.
So for instance if you wanted to add two arrays together on elements by elements basis you would just
say array plus array.
Now add the two arrays together.
In this case I'm just adding in array to itself.
So essentially every number's been doubled.
I can do the same thing for subtraction or even multiplication.
I can also perform array with scalar operations in very much the same manner so scalers mean just a
single number and went numb pi does is that basically broadcasts that number to every element in the
array so the operation occurs also on an element by element basis meaning if I want to.
Here is my array.
Add a hundred to every element in the array.
I could say plus and then the scalar itself.
And that would add 100 every element in the array.
And this also works for multiplication
division subtraction you name it.
So if I wanted subtract 100 from every atom in the break to say minus 100.
All right.
So those are basic arithmetic operations you can perform with either array on array operations or array
with scalar operations.
Something I want to show you is that a lot of times NUMP high will just issue a warning instead of outputting
error on certain mathematical operations.
So for instance if I try to say 1 divided by zero in Python I will get in that's an actual error has
zero division error which makes sense because you can't divide a number by zero.
However PI won't give you the same error.
So if I try to say a rate divided by Array.
Notice the very first element is zero.
I will try to say zero divided by zero which doesn't really make sense.
However none pi will issue a warning.
It will say invalid value encountered in truth like here and it'll just give you a null.
If you try to divide zero by zero everything else is OK for it says 1 divided by 1 is 1 2 divided by
2 is 1 as well.
Etc. etc..
However on the very first ones are divided by zero executed and gave you a name or no object back.
It didn't actually provide an error for you meaning you still get an output that's important to note
the distinction there.
That means if you have some sort of operation in your code you actually won't get an error.
The code will continue to run and instead he will just receive a warning if you tryna do an operation
that divides vides maybe another number by zero.
So for instance 1 divided by 0 instead of 0 the Vajda by zero.
You'll also get a warning.
But in this case Alexa's show infinity instead of a null.
So again you get a divide by zero and countered and true the vide warning here.
However it still executes the code and you get enough to signify infinity for the one divided by zero
.
At that very first elements.
All right.
So that's something to keep in mind as you're working with division and arrays that contain a number
are digits 0 and also a quick note as you can also do arrays with exponents.
I just say Asterix Asterix just like you would have Python and then either the scalar or the array one
.
So this is the array to the power of two.
So everything has been squared in the array Nel's discuss universal array function numpad comes with
many universal array functions which are essentially just mathematical operations.
You can use to perform the operation and broadcast across the entire array.
Let's go ahead and show some common ones.
For instance if you want to take the square root of every element in the array you can just say P that
s your t and then pass in the array itself.
And this will take the square root of everything in the array.
Similarly for calculating the exponential you can say that XP and in the array or maximum you can either
say the array that Max or you could also say that Max and pass in the array.
That's the same thing as calling the method off of it which we've seen earlier in the very first lecture
on them pyros.
You can even Neutrik the metric functions such a time and this will basically pass every element into
sine and there's co-sign and there's also logarithmic options.
You can say that log and if something doesn't work for instance the log of zero is technically negative
infinity you'll actually receive a runtime warning.
Divided by zero.
But it will give you negative infinity is the answer.
If you're wondering where you can find a list of all these universal array functions or reference you
can go ahead and check out the notebook and it has a link in there for the universal array functions
.
It will take you to link that looks like this.
This is the Empire raid documentation here for universal functions or you func.
And if you scroll down to the bottom of this page and again this link is in the notebook for this lecture
.
Now PI operations.
You'll see a whole list of all the universal functions you have available for you.
So you have basic math operations add subtract absolute remainder etc. Lague trigonometric functions
and then some more advanced functions.
That's just comparison functions maximum minimums floating functions etc..
If it's a very basic or common mathematical function you should probably visit this page first and see
if some pie already has it built in before you start creating your own function to deal that particular
mathematic operation.
You were trying to perform on your array.
Well at the very basic ones throughout the course and will remind you as we encountered them throughout
the rest of the course.
OK that's really all there is as far as basic operations on arrays.
You can just use basic arithmetic either on an array by irrate basis or with an array and a scalar basis
.
The only thing to watch out for is if you have a 0 and you're using divisional arrays.
Then the second part of this lecture just covered a universal array functions where it's find them.
Keep in mind that most common mathematical operations are already built into them by OK.
Thanks everyone and I'll see you at the next lecture