<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 NumPy Array Basics - Helpful Methods and Shortcuts
Step1:  Now we’ve got our array and we’ve got a method or two that we can use to create them. Let’s learn a bit more about some of the functions that arrays give us.
Step2:  First let’s checkout the type we’ve got, you can see it’s an ndarray which is the fundamental array in numpy. We can get the data type of the array. It’s worth elaborating a bit on dtypes or data types.
Unlike python, numpy has a variety of types. I’ll copy and paste the list here and speak to the different types.
Step3:  Data type   Description
- bool_
    - Boolean (True or False) stored as a byte
- int_
    - Default integer type (same as C long; normally either int64 or int32)
- intc 
    - Identical to C int (normally int32 or int64)
- intp 
    - Integer used for indexing (same as C ssize_t; normally either int32 or int64)
- int8 
    - Byte (-128 to 127)
- int16 
    - Integer (-32768 to 32767)
- int32 
    - Integer (-2147483648 to 2147483647)
- int64 
    - Integer (-9223372036854775808 to 9223372036854775807)
- uint8 
    - Unsigned integer (0 to 255)
- uint16 
    - Unsigned integer (0 to 65535)
- uint32 
    - Unsigned integer (0 to 4294967295)
- uint64 
    - Unsigned integer (0 to 18446744073709551615)
- float_
    - Shorthand for float64.
- float16 
    - alf precision float
Step4:  It’s worth starting that numpy arrays can be created in the fly simply by passing a list into the “array” function.
By default, numpy will try to guess what kinds of types you have in there but on creation you can also specify which type you would like. Now numpy arrays all have to have the same type, you can’t have a mix of floats and integers for example.
Step5:  This allows for consistent memory allocation and vectorization.
Sometimes you can get strange types when you're not quite expecting them.
Step6:  If you have any worry about what kind of array you’re creating, just specify the type.
Step7:  Numpy arrays also have some nifty functions that make our lives a lot easier. We can get the size, which is functionally equivalent to len in raw python. We can get the shape which gives us a hint as to where we’ll be going next, towards multidimensional arrays.
Step8:  We can also get things like the maximum, the minimum, the mean, the standard deviation, and variance. This makes it super easy to perform calculations quickly.
Step9:  We can also just get the locations of certain values with argmin, argmax.
Step10:  Now that we’ve seen how we can play around with arrays and some of their helper functions. We can elaborate on all the different ways of creating them. We’ve seen arange but we can actually do some cool things with it. We can count up or down. We can also fill in between two numbers. Say we want 1 to 2 broken up into 5 numbers.
Step11:  What about converting that to integers? We can use the as type method to convert it.
We can convert it to an integer
Step12:  a 32bit float or any other type
Step13:  Now there is one type that hasn’t been listed yet that is a bit difficult to describe. is nan or not a number. This will certainly come up and can throw off your analysis. Now nan’s are technically floats and can be created when you divide two 0 floating point numbers.
Step14:  If you’ve got a nan value in your array. It will throw off all your calculations. You’ve got to explicitly check for it in numpy.
Step15:  We’re going to build on this knowledge but at this point all that we need to know is that
arrays need to have the same values and 
nan values affect statistics derived from our arrays like the mean
<ASSISTANT_TASK:>
Python Code:
import sys
print(sys.version)
import numpy as np
print(np.__version__)
Explanation: NumPy Array Basics - Helpful Methods and Shortcuts
End of explanation
npa = np.arange(25)
npa
print(type(npa))
Explanation: Now we’ve got our array and we’ve got a method or two that we can use to create them. Let’s learn a bit more about some of the functions that arrays give us.
End of explanation
print(npa.dtype)
Explanation: First let’s checkout the type we’ve got, you can see it’s an ndarray which is the fundamental array in numpy. We can get the data type of the array. It’s worth elaborating a bit on dtypes or data types.
Unlike python, numpy has a variety of types. I’ll copy and paste the list here and speak to the different types.
End of explanation
np.array(range(20))
Explanation: Data type   Description
- bool_
    - Boolean (True or False) stored as a byte
- int_
    - Default integer type (same as C long; normally either int64 or int32)
- intc 
    - Identical to C int (normally int32 or int64)
- intp 
    - Integer used for indexing (same as C ssize_t; normally either int32 or int64)
- int8 
    - Byte (-128 to 127)
- int16 
    - Integer (-32768 to 32767)
- int32 
    - Integer (-2147483648 to 2147483647)
- int64 
    - Integer (-9223372036854775808 to 9223372036854775807)
- uint8 
    - Unsigned integer (0 to 255)
- uint16 
    - Unsigned integer (0 to 65535)
- uint32 
    - Unsigned integer (0 to 4294967295)
- uint64 
    - Unsigned integer (0 to 18446744073709551615)
- float_
    - Shorthand for float64.
- float16 
    - alf precision float: sign bit, 5 bits exponent, 10 bits mantissa
- float32 
    - ingle precision float: sign bit, 8 bits exponent, 23 bits mantissa
- float64 
    - ouble precision float: sign bit, 11 bits exponent, 52 bits mantissa
- complex_
    - Shorthand for complex128.
- complex64 
    - Complex number, represented by two 32-bit floats (real and imaginary components)
- complex128 
    - Complex number, represented by two 64-bit floats (real and imaginary component- s)
We’ve got all these different types that obviously have different abilities but let’s try creating some numpy arrays with those different types.
End of explanation
np.array([1.0,0,2,3])
np.array([1.0,0,2,3]).dtype
np.array([True,2,2.0]).dtype
Explanation: It’s worth starting that numpy arrays can be created in the fly simply by passing a list into the “array” function.
By default, numpy will try to guess what kinds of types you have in there but on creation you can also specify which type you would like. Now numpy arrays all have to have the same type, you can’t have a mix of floats and integers for example.
End of explanation
True == 1
np.array([True,2,2.0])
Explanation: This allows for consistent memory allocation and vectorization.
Sometimes you can get strange types when you're not quite expecting them.
End of explanation
np.array([True, 1, 2.0], dtype='bool_')
np.array([True, 1, 2.0], dtype='float_')
np.array([True, 1, 2.0], dtype='uint8')
npa
Explanation: If you have any worry about what kind of array you’re creating, just specify the type.
End of explanation
npa.size
npa.shape
Explanation: Numpy arrays also have some nifty functions that make our lives a lot easier. We can get the size, which is functionally equivalent to len in raw python. We can get the shape which gives us a hint as to where we’ll be going next, towards multidimensional arrays.
End of explanation
print(npa.min(), npa.max())
npa.std()
npa.var()
Explanation: We can also get things like the maximum, the minimum, the mean, the standard deviation, and variance. This makes it super easy to perform calculations quickly.
End of explanation
npa.argmin()
npa.argmax()
np.arange(1,10)
np.arange(10,1,-1)
Explanation: We can also just get the locations of certain values with argmin, argmax.
End of explanation
np.linspace(1,2,5)
np.linspace(0,10,11)
Explanation: Now that we’ve seen how we can play around with arrays and some of their helper functions. We can elaborate on all the different ways of creating them. We’ve seen arange but we can actually do some cool things with it. We can count up or down. We can also fill in between two numbers. Say we want 1 to 2 broken up into 5 numbers.
End of explanation
np.linspace(0,10,11).astype('int')
Explanation: What about converting that to integers? We can use the as type method to convert it.
We can convert it to an integer
End of explanation
np.linspace(0,10,11).astype(np.float32)
np.float32(5)
Explanation: a 32bit float or any other type
End of explanation
problem = np.array([0.])/np.array([0.])
# python throws an error because it knows something is wrong
problem[0]
np.nan
ar = np.linspace(0,10,11).astype(np.float32)
ar
ar[0] = np.nan
ar
Explanation: Now there is one type that hasn’t been listed yet that is a bit difficult to describe. is nan or not a number. This will certainly come up and can throw off your analysis. Now nan’s are technically floats and can be created when you divide two 0 floating point numbers.
End of explanation
ar.min()
ar.max()
ar.mean()
Explanation: If you’ve got a nan value in your array. It will throw off all your calculations. You’ve got to explicitly check for it in numpy.
End of explanation
np.isnan(ar.max())
Explanation: We’re going to build on this knowledge but at this point all that we need to know is that
arrays need to have the same values and 
nan values affect statistics derived from our arrays like the mean
End of explanation
<END_TASK>