working on it ...

Filters

Explore Public Snippets

Sort by

Found 1,478 snippets matching: dimension

    public by Geometry modified Aug 7, 2016  108137  0  5  0

    Reshape: Transforms a vector into a matrix of given dimensions.

    Transforms a vector into a matrix of given dimensions.
    /// <summary>
    ///   Transforms a vector into a matrix of given dimensions.
    /// </summary>
    /// 
    public static T[][] Reshape<T>(this T[] array, int rows, int cols, T[][] result, MatrixOrder order = MatrixOrder.Default)
    {
        if (order == MatrixOrder.CRowMajor)
        {
            int k = 0;
            for (int i = 0; i < rows; i++)
                for (int j = 0; j < cols; j++)
                    result[i][j] = array[k++];
        }
        else
        {
            int k = 0;
            for (int j = 0; j < cols; j++)
                for (int i = 0; i < rows; i++)
                    result[i][j] = array[k++];
        }
    
        return result;
    }

    public by pplant modified Jul 25, 2014  2884  2  6  2

    Scale Image to fit dimensions

    This snippet of code allows you to scale a image proportional such that it fits the provided dimensions.
    public static ImageIcon getScaledImage(ImageIcon srcImg, int w, int h){
    		int imgWidth = srcImg.getIconWidth();
    		int imgHeight = srcImg.getIconHeight();
    		
    		//Find the right width
    		if(imgWidth > w){
    			float sWidth = imgWidth-w;
    			float sFactor = (sWidth/imgWidth);
    			imgWidth = w;
    			imgHeight = (int) (imgHeight-(imgHeight*sFactor));
    		}
    		
    		//Find the right hight 
    		if(imgHeight > h){
    			float sHeight = imgHeight-h;
    			float sFactor = sHeight/imgHeight;
    			imgHeight = h;
    			imgWidth = (int) (imgWidth-(imgWidth*sFactor));
    		}
    		
    		BufferedImage resizedImg = new BufferedImage(imgWidth, imgHeight, BufferedImage.TYPE_INT_ARGB);
    		Graphics2D g2 = resizedImg.createGraphics();
    		g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    		g2.drawImage(srcImg.getImage(), 0, 0, imgWidth, imgHeight, null);
    		g2.dispose();
    		return new ImageIcon(resizedImg);
    	}

    public by Geometry modified Aug 7, 2016  1442  0  5  0

    Max: Gets the maximum values across one dimension of a matrix.

    Gets the maximum values across one dimension of a matrix.
    /// <summary>
    ///   Gets the maximum values across one dimension of a matrix.
    /// </summary>
    /// 
    public static T[] Max<T>(this T[][] matrix, int dimension, T[] result)
        where T : IComparable
    {
        int s = GetLength(matrix, dimension);
        var indices = new int[s];
        return Max(matrix, dimension, indices, result);
    }

    public by Geometry modified Aug 17, 2016  1174  0  6  0

    Vector: Creates a vector with the given dimension and starting values.

    Creates a vector with the given dimension and starting values.
    /// <summary>
    ///   Creates a vector with the given dimension and starting values.
    /// </summary>
    /// 
    [Obsolete("Please use Vector.Interval instead.")]
    public static double[] Vector(double a, double b, int points)
    {
        return Accord.Math.Vector.Interval(a, b, points);
    }

    public by Geometry modified Aug 7, 2016  1019  0  6  0

    Min: Gets the minimum values across one dimension of a matrix.

    Gets the minimum values across one dimension of a matrix.
    /// <summary>
    ///   Gets the minimum values across one dimension of a matrix.
    /// </summary>
    /// 
    public static T[] Min<T>(this T[][] matrix, int dimension)
        where T : IComparable
    {
        int s = GetLength(matrix, dimension);
        var result = new T[s];
        var indices = new int[s];
        return Min(matrix, dimension, indices, result);
    }

    public by Geometry modified Sep 25, 2016  903  0  3  0

    Min: Gets the minimum values across one dimension of a matrix.

    Gets the minimum values across one dimension of a matrix.
    /// <summary>
    ///   Gets the minimum values across one dimension of a matrix.
    /// </summary>
    /// 
    public static T[] Min<T>(this T[,] matrix, int dimension)
        where T : IComparable
    {
        int s = GetLength(matrix, dimension);
        var result = new T[s];
        var indices = new int[s];
        return Min(matrix, dimension, indices, result);
    }

    public by Geometry modified Aug 17, 2016  841  0  5  0

    GetLength: Gets the length of each dimension of an array.

    Gets the length of each dimension of an array.
    /// <summary>
    ///   Gets the length of each dimension of an array.
    /// </summary>
    /// 
    public static int[] GetLength(this Array array, bool deep = false)
    {
        if (deep && IsJagged(array))
        {
            var rest = GetLength(array.GetValue(0) as Array, deep);
            return array.Length.Concatenate(rest);
        }
    
        int[] vector = new int[array.Rank];
        for (int i = 0; i < vector.Length; i++)
            vector[i] = array.GetUpperBound(i) + 1;
        return vector;
    }

    public by Geometry modified Sep 25, 2016  337  0  3  0

    Max: Gets the maximum values across one dimension of a matrix.

    Gets the maximum values across one dimension of a matrix.
    /// <summary>
    ///   Gets the maximum values across one dimension of a matrix.
    /// </summary>
    /// 
    public static T[] Max<T>(this T[,] matrix, int dimension, T[] result)
        where T : IComparable
    {
        int s = GetLength(matrix, dimension);
        var indices = new int[s];
        return Max(matrix, dimension, indices, result);
    }

    public by Geometry modified Aug 7, 2016  49749  0  5  0

    FromData: Creates a new k-dimensional tree from the given points.

    Creates a new k-dimensional tree from the given points. The type of the value to be stored. The points to be added to the tree. Whether the given vector can be ordered in place. Passing true will change the original order of the vector. If set to false, all operations will be performed on an extra copy of the vector. A pop
    /// <summary>
    ///   Creates a new k-dimensional tree from the given points.
    /// </summary>
    /// 
    /// <typeparam name="T">The type of the value to be stored.</typeparam>
    /// 
    /// <param name="points">The points to be added to the tree.</param>
    /// <param name="inPlace">Whether the given <paramref name="points"/> vector
    ///   can be ordered in place. Passing true will change the original order of
    ///   the vector. If set to false, all operations will be performed on an extra
    ///   copy of the vector.</param>
    /// 
    /// <returns>A <see cref="KDTree{T}"/> populated with the given data points.</returns>
    /// 
    public static KDTree<T> FromData<T>(double[][] points, bool inPlace = false)
    {
        if (points == null)
            throw new ArgumentNullException("points");
    
        if (points.Length == 0)
            throw new ArgumentException("Insufficient points for creating a tree.");
    
        int leaves;
    
        var root = KDTree<T>.CreateRoot(points, inPlace, out leaves);
    
        return new KDTree<T>(points[0].Length, root, points.Length, leaves);
    }

    public by Geometry modified Aug 17, 2016  1130  0  6  0

    DimensionEquals: Checks whether two arrays have the same dimensions.

    Checks whether two arrays have the same dimensions.
    /// <summary>
    ///   Checks whether two arrays have the same dimensions.
    /// </summary>
    /// 
    public static bool DimensionEquals(this Array a, Array b)
    {
        if (a.Rank != b.Rank)
            return false;
        for (int i = 0; i < a.Rank; i++)
            if (a.GetLength(i) != b.GetLength(i))
                return false;
        return true;
    }
    • Public Snippets
    • Channels Snippets