'how to replace each element (of struct type) with another element in an array using Linq?

I have a Point struct:

public struct Point
{
    public Point(double x, double y, double z)
    {
        X = x;
        Y = y;
        Z = z;
    }

    public double X;
    public double Y;
    public double Z;
}

then in the following code, I am creating an array of points and then dividing each points by a value 2

//Create a test array of Points
Point[] testPointArray = new Point[2];
testPointArray[0] = new Point(2, 4, 8);
testPointArray[1] = new Point(6, 12, 24);

//Divide by 2
testPointArray = testPointArray.Select(point => point = new Point(point.X / 2, point.Y / 2, point.Z / 2)).ToArray();

Question: In the above code, I am using the new operator to replace each point with a newly created point. How can I directly make changes in the existing point (i.e. avoid creating new points)? I tried to do the following code, but the syntax is wrong:

testPointArray = testPointArray.Select(point =>
{
    point.X = point.X / 2;
    point.Y = point.Y / 2;
    point.Z = point.Z / 2;
}).ToArray();


Solution 1:[1]

testPointArray = testPointArray.Select(point =>
{
    point.X /= 2;
    point.Y /= 2;
    point.Z /= 2;
    return point;
}).ToArray();

In your example your lambda returns nothing - adding return point returns the mutated point for your select.

I agree with jalsh's comment that you should create new points, something like:

testPointArray = testPointArray.Select(point => new Point(point.X / 2, point.Y / 2, point.Z / 2))
            .ToArray();

Solution 2:[2]

I usually do stuff like this using matplotlib.pyplot.fill_between, with a low alpha (opacity of the shadow) and given the lower and upper bounds of the shaded area, which I'm assuming you could calculate from the frequency.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 TVOHM
Solution 2 Dominik Sta?czak