【发布时间】:2018-04-08 07:21:17
【问题描述】:
我想将我的经度从 -180 度到 180 度格式更改为数组的 0-360。有没有办法在不使用循环或 if 语句的情况下做到这一点?
lon_04_window = [ 1.39698386e-09 6.53551058e-02 1.30710210e-01 1.96065315e-01 2.61420419e-01 3.26775523e-01 3.92130628e-01 4.57485732e-01 5.22840836e-01 5.88195941e-01 6.53551045e-01 7.18906150e-01 7.84261254e-01 8.49616358e-01 9.14971463e-01 9.80326567e-01 1.04568167e+00 1.11103678e+00 1.17639188e+00 1.24174698e+00 1.30710209e+00 1.37245719e+00 1.43781230e+00 1.50316740e+00 1.56852251e+00 1.63387761e+00 1.69923272e+00 1.76458782e+00 1.82994292e+00 1.89529803e+00 1.96065313e+00 2.02600824e+00 2.09136334e+00 2.15671845e+00 2.22207355e+00 2.28742865e+00 2.35278376e+00 2.41813886e+00 2.48349397e+00 2.54884907e+00 2.61420418e+00 2.67955928e+00 2.74491439e+00 2.81026949e+00]
循环代码:
for i in range(len(lon)):
if lon[i] < 0:
lon[i] = lon[i]+360
【问题讨论】:
-
不,因为即使您为此使用任何函数,函数本身也必须使用循环。没有 if 也可以完成,但绝对不能没有循环。
-
还有什么你已经尝试过自己这样做?请查看How much research effort is expected?。 Stack Overflow 不是编码服务。您应该在发布之前研究您的问题并尝试自己编写代码。如果您遇到特定问题,请返回并附上Minimal, Complete, and Verifiable example 和您尝试过的内容的摘要,以便我们提供帮助。
-
你希望如何在没有迭代器的情况下迭代列表?
-
@cramopy 关键是我可以用循环或 if 语句很好地编写代码,但我正在寻找一种更快的方法。
-
@Rose 但在您的问题中,您要求
way without loop and if,而不是比您目前更快的方式。然后请编辑您的问题并添加您当前拥有的代码。
标签: python arrays python-2.7