Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6885313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:37:08+00:00 2026-05-27T05:37:08+00:00

I using this code to resize an array to new size: I want to

  • 0

I using this code to resize an array to new size:

I want to get an int array then return new array with new size that made by Lastarray’s Items’s average.
(for example resize an Image to new size)

    private int[] ResizeArray(int[] LastArray, int NewSize)
    {
        if (LastArray.GetUpperBound(0) == (NewSize-1))
        {
            return LastArray;
        }
        int i = 0;
        int j = 0;
        int c = 0;
        int[] NewArray = new int[NewSize];
        for (i = 1; i < NewSize; i++)
        {
            c = 0;
            for (j = (int)(i * ((double)LastArray.GetUpperBound(0) / (NewSize))); j <= ((i + 1) * ((double)LastArray.GetUpperBound(0) / (NewSize)) - 1); j++)
            {
                c += LastArray[j];
            }
            NewArray[i] = (int)(c / ((double)LastArray.Length / (NewSize)));
        }
        return NewArray;
    }

but Some times It returns unreasonable numbers!
Like this:

Last Array:
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365
365

New array:
0
421
280
421
280
421
280
421
421
280
421
280
421
280
421
421
280
421
280
421
280
421
421
280
421
280
421
280
421
421

another Last array:
83
84
89
90
91
92
93
94
95
96
97
99
100
101
102
104
105
106
109
111
112
114
116
118
120
121
123
125
127
128
130
132
133
134
136
137
138
140
141
142
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181

another New array:
0
103
71
109
75
116
80
125
131
91
141
98
151
103
159
164
111
170
115
176
119
182
185
125
191
129
197
133
203
206

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T05:37:09+00:00Added an answer on May 27, 2026 at 5:37 am

    You can’t just pick values like that and sum them up, you’ll need to do some averaging and calculation of the fraction of each old value that you want to put into the new values. Take a look at ‘resampling’ algorithms, e.g. http://drdobbs.com/184405045

    Here’s a simple resampler which upsamples the first array and then downsamples it. Not very efficient, but perhaps easier to understand:

        private static int[] ResizeArray(int[] oldArray, int newSize)
        {
            int oldSize = oldArray.Length;
            int rectangle = newSize * oldSize;
    
            var upsampled = Enumerable.Range(0, rectangle).Select(k => oldArray[k / newSize]).ToArray();
            var downSampled = Enumerable.Range(0, newSize).Select(j => Enumerable.Range(0, oldSize-1).Select(i => upsampled[j * oldSize + i])).Select(g => g.Average());
            return downSampled.Select(i => (int)i).ToArray();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using this code, and I get the stack trace that is listed below.
I'am using this code to resize image. But result is not fine, I want
I am using this code to dynamically resize text: function fontResize(){ $('.features').css('font-size', ($(window).width()/100) +
I'm using this code to resize an image on the iPhone: CGRect screenRect =
I'm using this code to resize images in CodeIgniter $config['image_library'] = 'gd2'; $config['source_image'] =
I have this code main.cpp #include <iostream> #include functs.h using namespace std; int main()
Using this code to zip a folder and it works perfect on small files
Im using this code for mysql connection $con = mysql_connect(localhost:/var/lib/mysql/mysql.sock, abc , xyz); if
While using this code to serialize an object: public object Clone() { var serializer
When using this code (simplified for asking): var rows1 = (from t1 in db.TABLE1

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.