Found 26504 Articles for Server Side Programming

How to use iota in Golang?

Mukul Latiyan
Updated on 22-Feb-2022 05:32:09

5K+ Views

Iota in Go is used to represent constant increasing sequences. When repeated in a constant, its value gets incremented after each specification. In this article, we will explore the different ways in which we can use iota in Go.Let's first consider a very basic example, where we will declare multiple constants and use iota.Example 1Consider the code shown belowpackage main import (    "fmt" ) const (    first = iota    second = iota    third = iota ) func main() {    fmt.Println(first, second, third) }OutputIf we run the command go run main.go, then we will get the ... Read More

How to parse Date strings in Golang?

Mukul Latiyan
Updated on 22-Feb-2022 05:28:17

14K+ Views

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

Anonymous goroutines in Golang

Mukul Latiyan
Updated on 22-Feb-2022 05:22:37

4K+ Views

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

Return element-wise title cased version of string or Unicode in Numpy

AmitDiwan
Updated on 21-Feb-2022 11:05:26

125 Views

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

Get the itemsize of the masked array in Numpy

AmitDiwan
Updated on 21-Feb-2022 11:03:07

194 Views

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

Get the information about the memory layout of the masked array in Numpy

AmitDiwan
Updated on 21-Feb-2022 10:59:02

187 Views

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

Compute the bit-wise XOR of two boolean arrays element-wise in Numpy

AmitDiwan
Updated on 21-Feb-2022 10:55:58

466 Views

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

Return the variance of the masked array elements along column axis in Numpy

AmitDiwan
Updated on 21-Feb-2022 10:51:09

134 Views

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

Compute the bit-wise OR of a 1D and a 2D array element-wise in Numpy

AmitDiwan
Updated on 21-Feb-2022 10:40:02

159 Views

To compute the bit-wise OR of a 1D and a 2D array element-wise, use the numpy.bitwise_or() method in Python Numpy. Computes the bit-wise OR 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.The where parameter is the condition broadcast over the input. At locations where the condition is True, the out array will be set to the ufunc result. Elsewhere, the out array will ... Read More

Return the variance of the masked array elements along row axis

AmitDiwan
Updated on 21-Feb-2022 10:36:54

119 Views

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 1, for row axisReturns 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

Advertisements