To compute the bit-wise OR of two arrays 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 retain its original value. ... Read More
To return the mask of a masked array, or full boolean array of False, use the ma.getmaskarray() method in Python Numpy. Returns the mask of arr as an ndarray if arr is a MaskedArray and the mask is not nomask, else return a full boolean array of False of the same shape as arr.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 ... Read More
In this article, we will understand how to add two binary strings in Java. A binary string is a sequence of numbers represented in bytes 0s and 1s.Below is a demonstration of the same −InputSuppose our input is −10101 10001OutputThe desired output would be −100110 AlgorithmStep 1- START Step 2- Create new scanner object Step 3- Enter two binary inputs Step 4- Define a carry flag Step 5- Use while condition to check if they are equal to 0 Step 6- If not, use the % operator and the carry flag to perform bitwise addition Step 7-Display it as result ... Read More
We know that substrings are a contiguous sequence of characters in a string, and in order to check whether a string contains a substring, we have two options available.The first approach is to use a built-in function called Contains() and the second approach is to make use a self-written logic for the same.The syntax for the Contains() function of the strings package is shown below.func Contains(s, substr string) boolIn the above syntax, there are two parameters inside the function Contains(). The first parameter is the string in which we are trying to find the pattern, and the second is the ... Read More
The reflect package in Go provides a very important function called DeepEqual() which can be used to compare composite types. The DeepEqual() function is used when we want to check if two data types are "deeply equal".Comparing slicesExample 1Consider the code shown belowpackage main import ( "fmt" "reflect" ) func main() { sl := []int{1, 2, 3} sl1 := []int{1, 2, 3} fmt.Println(reflect.DeepEqual(sl, sl1)) }OutputIf we run the command go run main.go on the above code, then we will get the following output in the terminal.trueComparing mapsExample 2Consider the code shown below.package main import ( ... Read More
We know that maps in Go contain key-value pairs. There are often instances where we would want to know that a certain key exists in a map or not, in such cases, we have two options available.The first approach is very naive, as in this approach, we basically iterate over the map with the help of the range clause and then compare each key to the key that we want to check if is available or not.And the second approach is a bit better, as we make use of the if statement with a bit of syntactic sugar.Let's first check ... Read More
We often want to replace certain strings or all the strings that match a pattern with some other string. In order to do that in Golang, we can either use the native functions that the strings package of Go's standard library provides us with or we can write the logic for the same on our own.In this article, we will see different examples, where we will use the two most used functions of the strings package. These functions are −strings.Replace()strings.ReplaceAll()Let's first consider the signature of these functions to know a little more about them.Syntax of strings.Replace()func Replace(s, old, new string, ... Read More
To read a CSV file in Go, the first thing that we need to make use of is the encoding/csv package that the Go standard library provides us with. The encoding/csv package contains different functions and methods that can be used when we want to read data from a CSV file.In this article, we will use the NewReader() function that the package provides, which takes one argument and that is basically the file that we want to open and then invoke the ReadAll() method on the file as well.Besides the encoding/csv package, we will also use the os package, which ... Read More
Many languages do provide a method similar to indexOf() where one can find the existence of a particular element in an array-like data structure. However, in Golang, there's no such method and we can simply implement it with the help of a for-range loop.Let's suppose we have a slice of strings, and we want to find out whether a particular string exists in the slice or not.Example 1Consider the code shown below.package main import ( "fmt" ) func Contains(sl []string, name string) bool { for _, value := range sl { if value == name ... Read More
Number parsing in Go is about converting the numbers that are present in string form to number form. By number form, we mean that these numbers can either be converted into integers, floats, etc.The most widely used package for number parsing is the "strconv" package that Go library provides us with. There are many cases that are present in the number parsing in Go, we will talk about all of these one by one in this article.The most basic approach is when we have a base 10 number that is actually present in a string form and we want to ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP