Announcement: All noncommercial projects registered to use Earth Engine beforeApril 15, 2025 mustverify noncommercial eligibility to maintain access. If you have not verified by September 26, 2025, your access may be on hold.

ee.Array.cos

  • Array.cos() computes the cosine of each element in an input array, assuming the input is in radians.

  • This operation returns an array containing the cosine values.

  • The input to Array.cos() must be an array.

On an element-wise basis, computes the cosine of the input in radians.

UsageReturns
Array.cos()Array
ArgumentTypeDetails
this:inputArrayThe input array.

Examples

Code Editor (JavaScript)

varπ=Math.PI;print(ee.Array([-π]).cos());// [-1]print(ee.Array([-π/2.0]).cos());// [Almost zero]print(ee.Array([0]).cos());// [1]print(ee.Array([π/2.0]).cos());// [Almost zero]print(ee.Array([π]).cos());// [-1]varstart=-π;varend=π;varpoints=ee.Array(ee.List.sequence(start,end,null,50));varvalues=points.cos();// Plot cos() defined above.varchart=ui.Chart.array.values(values,0,points).setOptions({viewWindow:{min:start,max:end},hAxis:{title:'x',viewWindowMode:'maximized',ticks:[{v:start,f:'-π'},{v:0,f:0},{v:end,f:'π'}]},vAxis:{title:'cos(x)',ticks:[{v:-1,f:-1},{v:0,f:0},{v:1,f:1}]},lineWidth:1,pointSize:0,});print(chart);

Python setup

See the Python Environment page for information on the Python API and usinggeemap for interactive development.

importeeimportgeemap.coreasgeemap

Colab (Python)

importmathimportaltairasaltimportpandasaspdπ=math.pidisplay(ee.Array([-π]).cos())# [-1]display(ee.Array([-π/2.0]).cos())# [Almost zero]display(ee.Array([0]).cos())# [1]display(ee.Array([π/2.0]).cos())# [Almost zero]display(ee.Array([π]).cos())# [-1]start=-πend=πpoints=ee.Array(ee.List.sequence(start,end,None,50))values=points.cos()df=pd.DataFrame({'x':points.getInfo(),'cos(x)':values.getInfo()})# Plot cos() defined above.alt.Chart(df).mark_line().encode(x=alt.X('x',axis=alt.Axis(values=[start,0,end])),y=alt.Y('cos(x)',axis=alt.Axis(values=[-1,0,1])))

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2023-10-06 UTC.