ee.Image.arrayReshape

यह फ़ंक्शन, एक जैसी शेप वाले पिक्सल वाली इमेज के ऐरे बैंड को नई शेप वाले ऐरे की इमेज में बदलता है. पिक्सल कई डाइमेंशन वाले हो सकते हैं.

इस्तेमालरिटर्न
Image.arrayReshape(lengths, dimensions)इमेज
आर्ग्यूमेंटटाइपविवरण
यह: imageइमेजऐरे की इमेज, जिसे फिर से आकार देना है.
lengthsइमेजएक बैंड वाली इमेज, जिसमें इनपुट इमेज के हर ऐक्सिस की नई लंबाई दी गई है. इसे पिक्सल के हिसाब से 1-डी ऐरे के तौर पर दिखाया गया है. हर शेप के ऐरे में, 'dimensions' की लंबाई की वैल्यू होनी चाहिए. अगर लंबाई में से कोई एक वैल्यू -1 है, तो उस ऐक्सिस के लिए लंबाई की वैल्यू इस तरह से कैलकुलेट की जाएगी कि कुल साइज़ एक जैसा रहे. खास तौर पर, [-1] शेप को 1-D में बदला जाता है. शेप के ज़्यादा से ज़्यादा एक कॉम्पोनेंट की वैल्यू -1 हो सकती है.
dimensionsपूर्णांकआउटपुट ऐरे के सभी पिक्सल के साथ शेयर किए गए डाइमेंशन की संख्या.

उदाहरण

कोड एडिटर (JavaScript)

// A function to print arrays for a selected pixel in the following examples.
function sampArrImg(arrImg) {
  var point = ee.Geometry.Point([-121, 42]);
  return arrImg.sample(point, 500).first().get('array');
}

// Create a 1D array image with length 6.
var arrayImg1D = ee.Image([0, 1, 2, 3, 4, 5]).toArray();
print('1D array image (pixel)', sampArrImg(arrayImg1D));
// [0, 1, 2, 3, 4, 5]

// Reshape the 1D 6-element array to a 2D 2 (row) x 3 (column) array. Notice
// that elements are filled row by row in the reshaped result.
var reshape2x3 = arrayImg1D.arrayReshape(ee.Image([2, 3]).toArray(), 2);
print('2D 2x3 array image (pixel)', sampArrImg(reshape2x3));
// [[0, 1, 2],
//  [3, 4, 5]]

// Use -1 to auto-determine a dimension length. For example, here we set
// 3 rows and let Earth Engine determine the number of columns needed.
var reshape3x_ = arrayImg1D.arrayReshape(ee.Image([3, -1]).toArray(), 2);
print('2D 3x? array image (pixel)', sampArrImg(reshape3x_));
// [[0, 1],
//  [2, 3],
//  [4, 5]]

// Flatten a 2D 2x3 array to 1D 6-element array.
var flattened = reshape2x3.arrayReshape(ee.Image([-1]).toArray(), 1);
print('2D array flattened to 1D', sampArrImg(flattened));
// [0, 1, 2, 3, 4, 5]

Python सेटअप करना

Python API और इंटरैक्टिव डेवलपमेंट के लिए geemap का इस्तेमाल करने के बारे में जानकारी पाने के लिए, Python एनवायरमेंट पेज देखें.

import ee
import geemap.core as geemap

Colab (Python)

# A function to print arrays for a selected pixel in the following examples.
def samp_arr_img(arr_img):
  point = ee.Geometry.Point([-121, 42])
  return arr_img.sample(point, 500).first().get('array')

# Create a 1D array image with length 6.
array_img_1d = ee.Image([0, 1, 2, 3, 4, 5]).toArray()
print('1D array image (pixel):', samp_arr_img(array_img_1d).getInfo())
# [0, 1, 2, 3, 4, 5]

# Reshape the 1D 6-element array to a 2D 2 (row) x 3 (column) array. Notice
# that elements are filled row by row in the reshaped result.
reshape2x3 = array_img_1d.arrayReshape(ee.Image([2, 3]).toArray(), 2)
print('2D 2x3 array image (pixel):', samp_arr_img(reshape2x3).getInfo())
# [[0, 1, 2],
#  [3, 4, 5]]

# Use -1 to auto-determine a dimension length. For example, here we set
# 3 rows and let Earth Engine determine the number of columns needed.
reshape3x_ = array_img_1d.arrayReshape(ee.Image([3, -1]).toArray(), 2)
print('2D 3x? array image (pixel):', samp_arr_img(reshape3x_).getInfo())
# [[0, 1],
#  [2, 3],
#  [4, 5]]

# Flatten a 2D 2x3 array to 1D 6-element array.
flattened = reshape2x3.arrayReshape(ee.Image([-1]).toArray(), 1)
print('2D array flattened to 1D:', samp_arr_img(flattened).getInfo())
# [0, 1, 2, 3, 4, 5]