最近我选择了Haskell.我发现我在Haskell中递归写入的一些基本数学算法实际上运行得更快,所以我想尝试一下.
我个人环顾四周,我找不到类似于pylab的库和Haskell的scipy.有没有人知道类似于它的东西或其他可能有用的数学库?
我所做的所有数学问题都与非线性常微分方程和偏微分方程有关,如果这有助于某人指出我的方向.
基本上是一个具有矩阵,图形,三角形,指数函数等的库.
给定一个动物列表,将其命名为m,其中包含
$bob
[1] 3
$ryan
[1] 4
$dan
[1] 1
Run Code Online (Sandbox Code Playgroud)
如何按数值对这个人进行排序?基本上我想看看我的代码看起来像这样
m=sort(m,sortbynumber)
$ryan
[1] 4
$bob
[1] 3
$dan
[1] 1
Run Code Online (Sandbox Code Playgroud)
不幸的是,我无法弄清楚。似乎是一个简单的解决方案。
我最近一直在使用报纸图书馆。我发现的唯一问题是我什么时候article.publish_date
总是得到None
。
class NewsArticle:
def __init__(self,url):
self.article = Article(url)
self.article.download()
self.article.parse()
self.article.nlp()
def getKeywords(self):
x = self.article.keywords
for i in range(0,len(x)):
x[i] = x[i].encode('ascii', 'ignore')
return x
return self.article.keywords
def getSummary(self):
return self.article.summary.encode('ascii', 'ignore')
def getAuthors(self):
x = self.article.authors
for i in range(0,len(x)):
x[i] = x[i].encode('ascii', 'ignore')
return x
def thumbnail_url(self):
return self.article.top_image.encode('ascii', 'ignore')
def date_made(self):
print self.article.publish_date
return self.article.publish_date
def get_videos(self):
x=self.article.movies
for i in range(0,len(x)):
x[i] = x[i].encode('ascii', 'ignore')
return x
def get_title(self): …
Run Code Online (Sandbox Code Playgroud) 就这么简单
我跑
ffmpeg -i my_stack.mp4 -vcodec h264 -acodec aac -strict -2 out_video.mov
Run Code Online (Sandbox Code Playgroud)
我有输出文件 out_video.mov
然后我尝试用quicktime播放器打开它并得到
The file isn’t compatible with QuickTime Player.
Run Code Online (Sandbox Code Playgroud)
有人知道我应该运行什么命令来解决这个问题吗?
谢谢
我正在从adj矩阵制作图形,这是我的代码,我尝试首先制作图形,然后对该图形进行加权,如下所示
for element in elements:
senMatrix[int(element.matrix_row)-1,int(element.matrix_column)-1]=1
G=nx.from_numpy_matrix(senMatrix)
for element in elements:
G[int(element.matrix_row)-1][int(element.matrix_column)-1]['weight']=int(element.value)
print str(G.nodes())
print str(G.edges())
avgClusterNumber=nx.average_clustering(G,weight='weight')
clusterList=nx.clustering(G,weight='weight')
graphDiameter=nx.diameter(G)
Run Code Online (Sandbox Code Playgroud)
前两个函数运行没有问题,但是最后一个直径函数引发了无限路径长度的问题,这使我认为没有边缘,节点或其他东西。
在这里看到错误
networkx.exception.NetworkXError: Graph not connected: infinite path length
Run Code Online (Sandbox Code Playgroud)
当我打印出来时,我得到这个
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, …
Run Code Online (Sandbox Code Playgroud) 所以我的约束函数没有被正确强加它会出现.
import numpy as np
import scipy.integrate as integrate
import scipy.interpolate as interpolate
import pylab as plt
import scipy.optimize as op
import math
def make_cons(parameter_guess):
cons=()
for i in range(0,len(parameter_guess)):
constraint = {'type': 'ineq', 'fun': lambda parameter_guess: -math.fabs(parameter_guess[i]) + 1 }
cons +=(constraint,)
# print cons
#cons=({'type': 'ineq', 'fun': lambda parameter_guess: -parameter_guess+ 1 })
return cons
def problem(N,IC):
t=np.linspace(0,5,1000)
tt=np.linspace(0,5+.5,N+1)
parameter_guess = .5*np.ones(len(tt))
res=op.minimize(cost_function, parameter_guess, args=(t,tt,IC), method='SLSQP',constraints=make_cons(parameter_guess))
true_param= res.x
print res.message
print true_param
generate_state_and_control(true_param,t,tt,IC)
def cost_function(parameter_guess,t,tt,IC):
#print parameter_guess
f_p = …
Run Code Online (Sandbox Code Playgroud) 我想要这样做,这样我就可以在重量数字上加上 $ 并将其设置为边缘文本。有聪明人可以告诉我做到这一点的技巧吗?例如,如果边缘的权重为 20,我希望边缘文本为“$20”
这是我的代码。
import json
import networkx as nx
import matplotlib.pyplot as plt
import os
import random
from networkx import graphviz_layout
G=nx.Graph()
for fn in os.listdir(os.getcwd()):
with open(fn) as data_file:
data = json.load(data_file)
name=data["name"]
name=name.split(',')
name = name[1] + " " + name[0]
cycle=data["cycle"]
contributions=data["contributions"]
contributionListforIndustry=[]
colorList=[]
colorList.append((random.uniform(0,1),random.uniform(0,1),random.uniform(0,1)))
for contibution in contributions:
amount=contibution["amount"]
industryName=contibution["name"]
metric=contibution["metric"]
colorList.append((random.uniform(0,1),random.uniform(0,1),random.uniform(0,1)))
contributionListforIndustry.append((industryName,amount))
G.add_edge(name,industryName,weight=amount, metricval=metric)
position=nx.graphviz_layout(G,prog='twopi',args='')
nx.draw(G,position,with_labels=False,node_color=colorList )
for p in position: # raise text positions
t= list(position[p])
t[1]=t[1]+10
position[p]=tuple(t)
nx.draw_networkx_edge_labels(G,position)
nx.draw_networkx_labels(G, position)
plt.title("Break …
Run Code Online (Sandbox Code Playgroud) 遇到这个任务有些麻烦.
目前我已经尝试了这个,我知道这是错误的,因为我不确定如何将L分为头部和尾部,但这是我想要的那种想法.
second(L,E) :- [H | E | T]
Run Code Online (Sandbox Code Playgroud)
我认为E必须在头部之后才能成为第二个元素.不过我是这门语言的新手,想要一些见解.如何从谓词的编写方式中获得这个头和尾.对此问题的一些见解将非常感激.谢谢.
我是prolog的新手,我正在尝试编写一个谓词,以便我可以判断一个列表是否是一个大小的列表.目前我有这个:
one([H | T]) :- H \= [] ,T == [].
Run Code Online (Sandbox Code Playgroud)
这有问题,至少我的逻辑是,如果H
它不是空的并且尾部没有任何东西,则必须是头部中存在某些东西并因此具有一个大小的情况.否则它没有.
非常感谢您解决此问题的一些见解.
我有几个问题
我正在编写这个名为rope的构造函数,我喜欢这个
data Rope = TextRope{ropeText :: String}
| ConcatRope{rope1 :: Rope, rope2 :: Rope}
| SubRope{subRopetext :: Rope, starting :: Integer, ending :: Integer}
deriving Show
Run Code Online (Sandbox Code Playgroud)
首先,当我制作像这样的TextRope
*Main> let s =TextRope "why"
*Main> s
TextRope {ropeText = "why"}
*Main>
Run Code Online (Sandbox Code Playgroud)
当我这样做时,想要获取构造函数的字符串,这就是为什么我并不确定.
对concat和sub构造函数也很好奇.具体来说,在我看来你正在调用这两个构造函数有事情发生,你正在返回将第1个绳索和第2个绳索连接在一起的结果,我不知道如何描述在这种语言中,你正在定义数据结构但不知何故返回的结果必须由结构计算
以下是这些功能如何工作的一些示例
> let tr = TextRope "Hello,"
> let sr = TextRope " world!"
> let hw = ConcatRope tr sr
> let ow = SubRope hw 4 4
> tr
Hello,
> sr
world!
> hw
Hello, …
Run Code Online (Sandbox Code Playgroud) <!DOCTYPE html>
<html>
<style >
.element{
font-size: 100px
}
.typed-cursor{
font-size: 100px
opacity: 1;
-webkit-animation: blink 0.7s infinite;
-moz-animation: blink 0.7s infinite;
animation: blink 0.7s infinite;
}
@keyframes blink{
10% { opacity:1; }
50% { opacity:0; }
100% { opacity:1; }
}
@-webkit-keyframes blink{
10% { opacity:1; }
50% { opacity:0; }
100% { opacity:1; }
}
@-moz-keyframes blink{
10% { opacity:1; }
50% { opacity:0; }
100% { opacity:1; }
}
</style>
<head>
<script src="jquery-2.1.4.js"></script>
<script type="text/javascript" src="typed.js"></script>
</head> …
Run Code Online (Sandbox Code Playgroud) python ×4
haskell ×2
matplotlib ×2
networkx ×2
prolog ×2
constructor ×1
datetime ×1
ffmpeg ×1
javascript ×1
jquery ×1
key-value ×1
numpy ×1
optimization ×1
quicktime ×1
r ×1
scipy ×1
typed ×1