我想在特定位置提取 shapefile 值。我使用的 shapefile 可以在这里找到,点击下载Download IHO Sea Areas。形状文件包含所有可能的海洋。
我可以阅读它并使用以下方法绘制它:
require("maptools")
require(rgdal)
require(sp)
ogrListLayers("World_Seas.shp")
shape <- readOGR("World_Seas.shp", layer="World_Seas")
Run Code Online (Sandbox Code Playgroud)
但是,我想提取特定位置的海值,例如
p <- c(-20, 40)
Run Code Online (Sandbox Code Playgroud) 我正在尝试解决一个链表问题,使用 python 在一次传递中找到中间元素。有人可以查看我的代码并建议执行此操作的最佳方式吗?
class Node(object):
def __init__(self, data=None, next=None):
self.data = data
self.next = next
def __str__(self):
return str(self.data)
def print_nodes(node):
while node:
print node
node = node.next
def find_middle(node):
while node:
current = node
node = node.next
second_pointer = node.next
next_pointer = second_pointer.next
if next_pointer is None:
return "Middle node is %s" % str(current)
node1 = Node(1)
node2 = Node(2)
node3 = Node(3)
node4 = Node(4)
node5 = Node(5)
node1.next = node2
node2.next = node3
node3.next = node4
node4.next …Run Code Online (Sandbox Code Playgroud) 我不确定为什么我不能像文档中所示对ModelViewSet进行PUT请求,但是PUT无法正常工作。有任何想法吗?我在下面包括了我的视图和序列化器。
class UserProfileViewSet(viewsets.ModelViewSet):
queryset = UserProfile.objects.all()
serializer_class = UserProfileSerializer
filter_fields = ('user', 'id', 'account_type')
class UserProfileSerializer(serializers.ModelSerializer):
class Meta:
model = UserProfile`
REST_FRAMEWORK = {
'DEFAULT_MODEL_SERIALIZER_CLASS':
'rest_framework.serializers.ModelSerializer',
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.TokenAuthentication',
),
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.AllowAny',
),
'DEFAULT_FILTER_BACKENDS': ('rest_framework.filters.DjangoFilterBackend',)
}
Run Code Online (Sandbox Code Playgroud) 我正在寻找一种方法将lm残差绑定到输入数据集.该方法必须添加NA缺失残差,残差应对应于正确的行.
样本数据:
N <- 100
Nrep <- 5
X <- runif(N, 0, 10)
Y <- 6 + 2*X + rnorm(N, 0, 1)
X[ sample(which(Y < 15), Nrep) ] <- NA
df <- data.frame(X,Y)
residuals(lm(Y ~ X,data=df,na.action=na.omit))
Run Code Online (Sandbox Code Playgroud)
残差应该与df绑定.
我正在寻找一些方法来使这个嵌套for循环更加pythonic.具体来说,如何迭代三个变量的唯一组合,如果数据存在于字典中,则写入文件?
foo,bar = {},{} #filling of dicts not shown
with open(someFile,'w') as aFile:
for year in years:
for state in states:
for county in counties:
try:foo[year,state,county],bar[state,county]
except:continue
aFile.write("content"+"\n")
Run Code Online (Sandbox Code Playgroud) 我是社区的新手,我在搜索在线提到的解决方案时多次尝试后发布了这个.但是,我无法解决它.
以下代码
dat<-read.csv("Harvard tutorial/Rgraphics/dataSets/EconomistData.csv")
g <- ggplot(dat, aes(dat$CPI, dat$HDI))
g1 <- g + theme_bw() + geom_smooth(method = "lm", formula = y ~log(x), se = FALSE, color = "Red", linetype = 1, weight = 3) +
geom_point(aes(color = Region), size = 4, fill = 4, alpha = 1/2, shape = 1) +
scale_x_continuous(name = "Corruption Perception Index", breaks = NULL) +
scale_y_continuous(name = "Human Development Index") +
scale_color_manual(name = "Region of the world", values = c("#24576D", "#099DD7", "#28AADC", "#248E84", "#F2583F", "#96503F")) …Run Code Online (Sandbox Code Playgroud) 我想用一个包含列表中值的索引位置的键创建字典.我正在使用python 2.7.考虑我的尝试:
LL = ["this","is","a","sample","list"]
LL_lookup = {LL.index(l):l for (LL.index(l), l) in LL}
# desired output
print LL_lookup[1]
>> is
Run Code Online (Sandbox Code Playgroud)
我认识到在这个例子中不需要字典 - LL[1]会产生相同的结果.尽管如此,我们可以想象一种情况,其中1)字典是优选的,给出更复杂的例子,和b)字典查找可以通过大量迭代产生边际性能增益.
python ×4
r ×3
algorithm ×1
dataframe ×1
dictionary ×1
django ×1
for-loop ×1
ggplot2 ×1
gis ×1
iterator ×1
linked-list ×1
list ×1
plyr ×1
python-2.7 ×1
regression ×1
rgdal ×1