Tag: Array
Create a Singly Linked List from an array
Suppose we have an int array and we want to create it into a singly linked list from it. Singly Linked List Our Node structure is, Advertisements struct node { Â Â Â int value; Â Â Â node * nextPtr;Â Â Â Â Â Â node(int val) Â Â Â { Â Â Â Â Â Â value = val; Â Â Â Â Â Â nextPtr = NULL;Â Â Â Â Â …
Create a Binary Search Tree from an array
Lets discuss how to create a BST From an array. Advertisements Tree’s node structure is as follows, typedef struct node { int value; node * pLeft; node * pRight; node(int val = 0) { value = val; pRight = NULL; pLeft = NULL; } }node; Now create a getBST function that accepts an integer pointer …
Initializing a HashSet from an Array or a Collection
In this Article we will discuss how to initialize a HashSet using a Array or a Collection. HashSet has a Constructor that receives a Collection as an argument and initializes the new Set with the elements of passed collection object. Advertisements public HashSet(Collection<? extends E> c) Initializing a HashSet with an array Suppose we need to …
Initializing a HashSet from an Array or a CollectionRead More
How to convert a HashSet into an array in Java
In this article we will discuss how to convert a HashSet in to an array. Each collection that provides a member function toArray() i.e. Advertisements public <T> T[] toArray(T[] a) It iterates through all the elements of Collection (HashSet in our case) and set the each elements in the passed argument array []a. But if array …
How to Merge an Array in a HashSet in Java
In this article we will discuss how to merge an array in a HashSet HashSet has a member function addAll() that can add a collection into to a HashSet. But this Collection should be of Same Type as of HashSet or of its Base Class. Advertisements public boolean addAll(Collection<? extends E> c)  It will add the each …
np.array() : Create Numpy Array from list, tuple or list of lists in Python
In this article we will discuss how to create a Numpy Array from a sequence like list or tuple etc. Also, how to create a 2D numpy Numpy Array from nested sequence like lists of lists. np.array() – Creating 1D / 2D Numpy Arrays from lists & tuples in Python To install the python’s numpy module …
np.array() : Create Numpy Array from list, tuple or list of lists in PythonRead More
Select Subarray By Index from NumPy Array
In this article we will discuss how to select an element or a sub array from a Numpy Array by index. Let’s create a Numpy Array using numpy.arange() Advertisements # Create a numpy ndArray npArray = np.arange(1, 20, 2) print(npArray) Contents of the Numpy Array is as follows, [ 1 3 5 7 9 11 …
Find max value & its index in Numpy Array | numpy.amax()
In this article we will discuss how to get the maximum / largest value in a Numpy array and its indices using numpy.amax(). numpy.amax() Python’s numpy module provides a function to get the maximum value from a Numpy array i.e. Advertisements numpy.amax(a, axis=None, out=None, keepdims=<no value>, initial=<no value>) Arguments : a : numpy array from …
Find max value & its index in Numpy Array | numpy.amax()Read More
numpy.arange() : Create a Numpy Array of evenly spaced numbers in Python
In this article we will discuss how to create a Numpy array of evenly spaced numbers over a given interval using numpy.arrange(). numpy.arrange() Python’s numpy module provides a function to create an Numpy Array of evenly space elements within a given interval i.e. numpy.arange([start, ]stop, [step, ]dtype=None) Arguments: Advertisements start : It’s the start value …
numpy.arange() : Create a Numpy Array of evenly spaced numbers in PythonRead More
Python : Find unique values in a numpy array with frequency & indices | numpy.unique()
In this article we will discuss how to find unique values / rows / columns in a 1D & 2D Numpy array. Also how to find their index position & frequency count using numpy.unique(). numpy.unique() Python’s numpy module provides a function to find the unique elements in a numpy array i.e. Advertisements numpy.unique(ar, return_index=False, return_inverse=False, return_counts=False, …
Python : Find unique values in a numpy array with frequency & indices | numpy.unique()Read More