我想在 2D numpy 数组上应用掩码。但它不能正常工作。假设我有
val(lat, lon)  ---> my 2D array (20, 30)
Mask_lat = np.ma.masked_array(lat, mask=latmask)  ---> masked lat (5,)
Mask_lon = np.ma.masked_array(lon, mask =lonmask)   ---> masked lon (8,)
Maks_val = np.ma.masked_array(val, mask=mask_lat_lon) ---> ?
我不知道我怎么能通过一个正确的mask_lat_lon被屏蔽val (5,8)。如果有人指导我,我将不胜感激。
先感谢您。
所以我想在Python中抓取目录下的第一个文件。我知道我可以这样做:
first_file = [join(path, f) for f in os.listdir(path) if isfile(join(path, f))][0]
但它很慢。有没有更好的解决办法?谢谢!
我有一个if声明:
rules = input ("Would you like to read the instructions? ")
rulesa = "Yes"
if rules == rulesa:
    print  ("No cheating")
else: print ("Have fun!")
我希望用户能够回答Yes,YES,yES,yes或任何其他大小写,并且代码知道他们的意思是Yes.
我有一个字符串和列表列表.我想使用反转列表中的每个可迭代map.我目前的设置如下:
forwards_list = [
  'abc',
  'def',
  [1, 2, 3, 4, 5],
]
def reverse(item):
  object_type = type(item)
  return object_type(reversed(item))
backwards_list = list(map(reverse, forwards_list))
print(backwards_list)
输出:
['<reversed object at 0x000000000A29A5C0>',
'<reversed object at 0x000000000A29A5C0>',
[5, 4, 3, 2, 1]]
期望的输出:
['cba', 'fed', [5, 4, 3, 2, 1]]
问题似乎是list(reversed([]))回报[],而str(reversed(''))回报'<reversed object at 0x000000000A335898>'
.有人可以帮忙吗?
无论如何在没有for循环的情况下使用一个固定参数的列表上的用户映射?例如
def addx(x, y):
  return x + y
print map(addx, 10, [10,20])
输出应为20和30
谢谢