Found 10476 Articles for Python

Return the base 2 logarithm of the input array in Python

AmitDiwan
Updated on 24-Feb-2022 10:13:17

839 Views

To return the base 2 logarithm of the input array, use the numpy.log2() method in Python Numpy The method returns Base-2 logarithm of x. This is a scalar if x is a scalar. The 1st parameter, x is the input value, array-like. The 2nd parameter is out, a location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshlyallocated array is returned. A tuple must have length equal to the number of outputs.The 3rd parameter is where, the condition is broadcast over the input. At ... Read More

Compute the Natural logarithm for complex-valued input in Python

AmitDiwan
Updated on 24-Feb-2022 10:11:04

559 Views

The natural logarithm log is the inverse of the exponential function, so that log(exp(x)) = x. The natural logarithm is logarithm in base e. The method returns the natural logarithm of x, element-wise. This is a scalar if x is a scalar. The 1st parameter is the input value, array-like. The 2nd parameter is out, a location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly-allocated array is returned. A tuple (possible only as a keyword argument) must have length equal to the number ... Read More

Convert an array of datetimes into an array of strings with UTC timezone in Python

AmitDiwan
Updated on 24-Feb-2022 10:08:49

535 Views

To convert an array of datetimes into an array of strings, use the numpy.datetime_as_string() method in Python Numpy. The method returns an array of strings the same shape as the input array. The first parameter is the array of UTC timestamps to format. The second parameter is the "timezone", the Timezone information to use when displaying the datetime. If ‘UTC’, end with a Z to indicate UTC time.StepsAt first, import the required library −import numpy as npCreate an array of datetime. The 'M' type specifies datetime −arr = np.arange('2022-02-20T03:25', 6*60, 60, dtype='M8[m]')Displaying our array −print("Array...", arr)Get the datatype −print("Array datatype...", ... Read More

Convert an array of datetimes into an array of strings in Python

AmitDiwan
Updated on 24-Feb-2022 08:08:22

191 Views

To convert an array of datetimes into an array of strings, use the numpy.datetime_as_string() method in Python Numpy. The method returns an array of strings the same shape as the input array. The first parameter is the array of UTC timestamps to formatStepsAt first, import the required library −import numpy as npCreate an array of datetime. The 'M' type specifies datetime −arr = np.arange('2022-02-20T02:10', 6*60, 60, dtype='M8[m]')Displaying our array −print("Array...", arr)Get the datatype −print("Array datatype...", arr.dtype) Get the dimensions of the Array −print("Array Dimensions...", arr.ndim)Get the shape of the Array −print("Our Array Shape...", arr.shape)Get the number of elements of the ... Read More

Return the length of a string array element-wise in Python

AmitDiwan
Updated on 24-Feb-2022 08:05:40

2K+ Views

To return the length of a string array element-wise, use the numpy.char.str_len() method in Python Numpy. The method returns an output array of integers.StepsAt first, import the required library −import numpy as npCreate a One-Dimensional array of strings −arr = np.array(['Amy', 'Scarlett', 'Katie', 'Brad', 'Tom'])Displaying our array −print("Array...", arr)Get the datatype −print("Array datatype...", arr.dtype) Get the dimensions of the Array −print("Array Dimensions...", arr.ndim)Get the shape of the Array −print("Our Array Shape...", arr.shape)Get the number of elements of the Array −print("Number of elements in the Array...", arr.size)To return the length of a string array element-wise, use the numpy.char.str_len() method −print("Result (length ... Read More

Return the highest index in the string where substring is found in a range using Python rindex()

AmitDiwan
Updated on 24-Feb-2022 08:04:04

138 Views

Return the highest index in the string where substring sub is found using the numpy.char.rindex() method in Python Numpy. The method returns the output array of ints. Raises ValueError if sub is not found. The first parameter is the input array. The second parameter is the substring to be searched. The third and fourth parameter are optional arguments, wherein start and end are interpreted as in slice notation.StepsAt first, import the required library −import numpy as npCreate a One-Dimensional array of strings −arr = np.array(['KATIE', 'KATE', 'BRATleukATp'])Displaying our array −print("Array...", arr)Get the datatype −print("Array datatype...", arr.dtype) Get the dimensions of ... Read More

For each element return the highest index in the string where substring is found in a range in Python

AmitDiwan
Updated on 24-Feb-2022 07:57:23

236 Views

To return the highest index in the string where substring sub is found, use the numpy.char.rfind() method in Python Numpy. The method returns the output array of ints. Returns -1 if sub is not found.The first parameter is the input array. The second parameter is the substring to be searched. The third and fourth parameter are optional arguments, wherein start and end are interpreted as in slice notation.StepsAt first, import the required library −import numpy as npCreate a One-Dimensional array of strings −arr = np.array(['KATIE', 'JOHN', 'AmY', 'BRATleuATp'])Displaying our array −print("Array...", arr)Get the datatype −print("Array datatype...", arr.dtype) Get the dimensions ... Read More

For each element return the highest index in the string where substring is found in Python

AmitDiwan
Updated on 24-Feb-2022 07:55:06

112 Views

To return the highest index in the string where substring sub is found, use the numpy.char.rfind() method in Python Numpy. The method returns the output array of ints. Returns -1 if sub is not found. The first parameter is the input array. The second parameter is the substring to be searchedStepsAt first, import the required library −import numpy as npCreate a One-Dimensional array of strings −arr = np.array(['KATIE', 'JOHN', 'AmY', 'BRATleuATp'])Displaying our array −print("Array...", arr)Get the datatype −print("Array datatype...", arr.dtype) Get the dimensions of the Array −print("Array Dimensions...", arr.ndim)Get the shape of the Array −print("Our Array Shape...", arr.shape)Get the number ... Read More

Return a boolean array where the string element in array begins with a given prefix but test begin and end in Python

AmitDiwan
Updated on 24-Feb-2022 07:53:11

432 Views

To return a boolean array which is True where the string element in array begins with prefix, use the numpy.char.startswith() method in Python Numpy. The method outputs an array of bools. The first parameter is the input array. The second parameter is the prefix. With optional start parameter, test beginning at that position. With optional end parameter, stop comparing at that position.StepsAt first, import the required library −import numpy as npCreate a One-Dimensional array of strings −arr = np.array(['KATIE', 'JOHN', 'KATE', 'KmY', 'BRAD'])Displaying our array −print("Array...", arr)Get the datatype −print("Array datatype...", arr.dtype) Get the dimensions of the Array −print("Array Dimensions...", ... Read More

For each element return the lowest index in the string where substring is found in Python

AmitDiwan
Updated on 24-Feb-2022 07:49:51

136 Views

To return the lowest index in the string where substring sub is found, use the numpy.char.find() method in Python Numpy. The method returns the output array of ints. Returns -1 if sub is not found. The first parameter is the input array. The second parameter is the substring to be searchedStepsAt first, import the required library −import numpy as npCreate a One-Dimensional array of strings −arr = np.array(['KATIE', 'JOHN', 'KATE', 'AmY', 'BRADley'])Displaying our array −print("Array...", arr)Get the datatype −print("Array datatype...", arr.dtype) Get the dimensions of the Array −print("Array Dimensions...", arr.ndim)Get the shape of the Array −print("Our Array Shape...", arr.shape)Get the ... Read More

Advertisements