When it comes to parsing Date strings in Go, we can use the Parse function that is provided by the time package. In Go, we don't use codes like most other languages to represent the component parts of a date/time string. Instead, Go uses the mnemonic device - standard time as a reference.For example, the reference time can either look like this −Mon Jan 2 14:10:05 MST 2020 (MST is GMT-0700)Or, it can look like this as well.01/02 03:04:10PM '20 -0700SyntaxThe syntax of the Parse() function is shown below.func Parse(layout, value string) (Time, error)The Parse function takes a layout and ... Read More
In order to be able to understand the anonymous goroutines, we must be aware of the existence of anonymous functions and goroutines. We will first explore the anonymous functions that are the real reason behind the motivation of anonymous goroutines and then we will learn a little about what goroutines are, before finally checking a few examples of anonymous goroutines.Anonymous functionsIn Golang, anonymous functions are those functions that don't have any name. Simply put, anonymous functions don't use any variables as a name when they are declared.We know that we declare a function with a similar syntax as shown below.func ... Read More
In this article, we will understand how to print a multiplication table. Multiplication table is created by iterating the required input 10 times using a for loop and multiplying the input value with numbers from 1 to 10 in each iteration.Below is a demonstration of the same −InputSuppose our input is −Input : 16OutputThe desired output would be −The multiplication table of 16 is : 16 * 1 = 16 16 * 2 = 32 16 * 3 = 48 16 * 4 = 64 16 * 5 = 80 16 * 6 = 96 16 * 7 = 112 ... Read More
In this article, we will understand how to round a number to n decimal places. Rounding of decimal values are done using the CEIL or FLOOR functions.Below is a demonstration of the same −InputSuppose our input is −Input : 3.1415OutputThe desired output would be −Output : 3.2 AlgorithmStep 1 - START Step 2 - Declare a float variable values namely my_input. Step 3 - Read the required values from the user/ define the values Step 4 – Use the CEIL function to round the number to the required decimal places. In this example we are rounding up to 2 decimal ... Read More
In this article, we will understand how to iterate over enum objects. Enum is a datatype that represents a small collection of objects.Below is a demonstration of the same −InputSuppose our input is −Enum objects are defined as : red, blue, green, yellow, orangeOutputThe desired output would be −Printing the Objects: red blue green yellow orangeAlgorithmStep 1 – START Step 2 - Declare the objects of Enum function namely red, blue, green, yellow, orange Step 3 – Using a for loop, iterate over the objects of the enum function and print each object. Step 4- StopExample 1enum Enum { ... Read More
To return element-wise title cased version of string or unicode, use the numpy.char.title() method in Python Numpy. Title case words start with uppercase characters, all remaining cased characters are lowercase.The function title() returns an output array of str or unicode, depending on input type. The numpy.char module provides a set of vectorized string operations for arrays of type numpy.str_ or numpy.bytes_.StepsAt 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...", ... Read More
To get the itemsize of the Masked Array, use the ma.MaskedArray.itemsize attribute in Numpy. A masked array is the combination of a standard numpy.ndarray and a mask. A mask is either nomask, indicating that no value of the associated array is invalid, or an array of booleans that determines for each element of the associated array whether the value is valid or not.StepsAt first, import the required library −import numpy as np import numpy.ma as maCreate a numpy array using the numpy.array() method −arr = np.array([[35, 85], [67, 33]]) print("Array...", arr) print("Array type...", arr.dtype) print("Array itemsize...", arr.itemsize)Get the dimensions of ... Read More
To get the information about the memory layout of the masked array, use the ma.MaskedArray.flags in Numpy. Masked arrays are arrays that may have missing or invalid entries. The numpy.ma module provides a nearly work-alike replacement for numpy that supports data arrays with masks.A masked array is the combination of a standard numpy.ndarray and a mask. A mask is either nomask, indicating that no value of the associated array is invalid, or an array of booleans that determines for each element of the associated array whether the value is valid or not.StepsAt first, import the required library −import numpy as ... Read More
To compute the bit-wise XOR of two boolean arrays element-wise, use the numpy.bitwise_xor() method in Python Numpy.Computes the bit-wise XOR of the underlying binary representation of the integers in the input arrays. This ufunc implements the C/Python operator ^.The 1st and 2nd parameter are the arrays, only integer and boolean types are handled. If x1.shape != x2.shape, they must be broadcastable to a common shape.StepsAt first, import the required library −import numpy as npCreating two numpy boolean arrays using the array() method −arr1 = np.array([[False, False, False], [True, False, True]]) arr2 = np.array([[False, True, False], [False, False, False]])Display ... Read More
To return the variance of the masked array elements, use the ma.MaskedArray.var() in Numpy. The axis is set using the axis parameter. The axis is set to 0, for column axis.Returns the variance of the array elements, a measure of the spread of a distribution. The variance is computed for the flattened array by default, otherwise over the specified axis.The “axis” parameter is the axis or axes along which the variance is computed. The default is to compute the variance of the flattened array. If this is a tuple of ints, a variance is performed over multiple axes, instead of ... Read More