这个问题借给Joe Kington的代码(如何用matplotlib在一个小区的角上插入一个小图片?):
import matplotlib.pyplot as plt
import Image
import numpy as np
im = Image.open('/home/jofer/logo.png')
height = im.size[1]
# We need a float array between 0-1, rather than
# a uint8 array between 0-255
im = np.array(im).astype(np.float) / 255
fig = plt.figure()
plt.plot(np.arange(10), 4 * np.arange(10))
# With newer (1.0) versions of matplotlib, you can
# use the "zorder" kwarg to make the image overlay
# the plot, rather than hide behind it... (e.g. zorder=10)
fig.figimage(im, 0, fig.bbox.ymax …
Run Code Online (Sandbox Code Playgroud) 通过写作
import igraph
g = igraph.Graph()
g.add_vertices(6)
g.add_edges([(0,1),(0,3),(0,4),(0,5),(1,2),(2,4),(2,5),(3,0),(3,2),(3,5),(4,5),(3,3)])
A=g.get_adjacency()
Run Code Online (Sandbox Code Playgroud)
我得到了图g的邻接矩阵,作为Matrix对象.我想通过使用,例如,计算其特征值numpy.linalg.eigvals()
.此方法将numpy数组对象作为参数.如何将Matrix对象转换为numpy数组对象?我试过用
X=numpy.matrix(A)
Run Code Online (Sandbox Code Playgroud)
但是它产生了两种混合物,并且无法计算特征值.
我正在为确定父级表的表生成层次结构。
即使在收到有关太大框架的错误之后,也使用以下配置:
--conf spark.yarn.executor.memoryOverhead=1024mb \
--conf yarn.nodemanager.resource.memory-mb=12288mb \
--driver-memory 32g \
--driver-cores 8 \
--executor-cores 32 \
--num-executors 8 \
--executor-memory 256g \
--conf spark.maxRemoteBlockSizeFetchToMem=15g
Run Code Online (Sandbox Code Playgroud)
import org.apache.log4j.{Level, Logger};
import org.apache.spark.SparkContext;
import org.apache.spark.sql.{DataFrame, SparkSession};
import org.apache.spark.sql.functions._;
import org.apache.spark.sql.expressions._;
lazy val sparkSession = SparkSession.builder.enableHiveSupport().getOrCreate();
import spark.implicits._;
val hiveEmp: DataFrame = sparkSession.sql("select * from db.employee");
hiveEmp.repartition(300);
import org.apache.spark.sql.functions._;
val nestedLevel = 3;
val empHierarchy = (1 to nestedLevel).foldLeft(hiveEmp.as("wd0")) { (wDf, i) =>
val j = i - 1
wDf.join(hiveEmp.as(s"wd$i"), col(s"wd$j.parent_id".trim) === col(s"wd$i.id".trim), …
Run Code Online (Sandbox Code Playgroud) 我正在编写一个小型NLP算法,我需要执行以下操作:
对于列表中的每个字符串x ["this", "this", "and", "that"]
,如果字符串x
和下一个字符串相同,我想打印字符串.
我用来lxml
从html页面检索标签的属性。html页面的格式如下:
<div class="my_div">
<a href="/foobar">
<img src="my_img.png">
</a>
</div>
Run Code Online (Sandbox Code Playgroud)
我用来检索<a>
标记内的url 和相同标记内的src
值的python脚本是这样的:<img>
<div>
from lxml import html
...
tree = html.fromstring(page.text)
for element in tree.xpath('//div[contains(@class, "my_div")]//a'):
href = element.xpath('/@href')
src = element.xpath('//img/@src')
Run Code Online (Sandbox Code Playgroud)
为什么我没有得到琴弦?
我试图在 matplotlib 上绘制 2 条不同的曲线,但其中一个图需要散点图,或者没有连接点的线。有没有办法做到这一点?现在,我的绘图代码是:
fig, ax1 = plt.subplots()
ax2 = ax1.twinx()
ax1.plot(epoch, list_of_gas, 'b')
ax2.plot(temp_times, temperatures, 'r')
ax1.set_ylabel('Pressure (torr)', color='b')
ax2.set_ylabel('Temperature (Celcius)', color='r')
ax1.set_title(folder + ' - ' + gas)
ax1.set_xlabel('time (seconds)')
ax1.set_xlim([0, 1000000])
ax2.set_ylim([0,425])
ax1.set_yscale('log')
ax1.set_ylim([ymin,ymax])
plt.show()
Run Code Online (Sandbox Code Playgroud)
但是,我想要ax1.scatter(epoch, list_of_gas, 'b')
,但是您不能使用 2 轴散点图。有谁知道解决这个问题的方法?喜欢删除连接点的线?
我有 2 个大数据帧要根据关联键进行合并。使用join
需要更长的时间才能完成任务。
我看到cogroup
在 Apache Spark中使用优于加入。任何人都可以指出如何cogroup
在 DataFrames上使用或建议更好的方法来合并 2 个大型 DataFrames。
谢谢
我需要将不同形状的矩阵,M和N与有限大小的MxN相乘.
我想一个例子会更清楚:
A(形状:4x4)=
0 3 0 0
0 0 4 0
0 0 0 3
0 0 0 0
Run Code Online (Sandbox Code Playgroud)
B(形状:7x7)=
3 0 0 0 0 0 0
0 2 0 0 0 0 0
0 0 1 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 -1 0 0
0 0 0 0 0 -2 0
0 0 0 0 0 0 -3
Run Code Online (Sandbox Code Playgroud)
结果,我想要一个形状矩阵(4*7 x 4*7),这意味着(28 x 28)如下:
0 3*B 0 0
0 0 …
Run Code Online (Sandbox Code Playgroud) import os, glob, numpy as np
files = glob.glob('*.jpg')
indices = np.array([i for i,j in enumerate(files)])
selected_indices = np.random.choice(indices,500,replace=False)
print files[selected_indices]
Run Code Online (Sandbox Code Playgroud)
我无法将索引转换为文件.这样做的好方法是什么?
view.py
如果我使用的话,我有一段代码可以工作from datetime import time
:
工作代码:
from datetime import time, ...
times = []
for i in range(0, 24*4):
times.append((datetime.combine(date.today(),
time()) + timedelta(minutes=15) * i).time().strftime("%I:%M %p"))
Run Code Online (Sandbox Code Playgroud)
不幸的是,如果我有一个到位,我有我的另一代码view.py
被使用import time
到AM / PM时间转换为24小时分贝友好的格式将无法工作,如果from datetime import time
是到位。
码:
import time
mytime = time.strftime('%H:%M:%S', time.strptime(mytime, '%I:%M %p'))
Run Code Online (Sandbox Code Playgroud)
所以问题是:
import time
?import datetime
?我正在尝试将.flo文件作为numpy 2Channels图像读取.
格式描述如下:
".flo" file format used for optical flow evaluation
Stores 2-band float image for horizontal (u) and vertical (v) flow components.
Floats are stored in little-endian order.
A flow value is considered "unknown" if either |u| or |v| is greater than 1e9.
bytes contents
0-3 tag: "PIEH" in ASCII, which in little endian happens to be the float 202021.25
(just a sanity check that floats are represented correctly)
4-7 width as an integer
8-11 height as an integer …
Run Code Online (Sandbox Code Playgroud) 我想用四个numpy数组对列表进行排序.
import numpy as np
import datetime
time_origin=[]
filelist=['3.csv','2.csv','1.csv','4.csv']
for i in np.arange(4):
time_origin.append(np.loadtxt(
filelist[i],delimiter=',',skiprows=1,usecols=(0,),unpack=True))
time_origin.sort()
Run Code Online (Sandbox Code Playgroud)
但是,它不起作用.
预期结果:
例如:
a=[array[1,2,3,4],array[6,2],array[0,12,1,4,5]]
Run Code Online (Sandbox Code Playgroud)
我想根据每个数组的长度对其进行排序
预期的结果是:
a=[array[6,2],array[1,2,3,4],array[0,12,1,4,5]]
Run Code Online (Sandbox Code Playgroud) python ×10
numpy ×4
apache-spark ×2
image ×2
c++ ×1
compare ×1
dataframe ×1
datetime ×1
file-format ×1
hadoop-yarn ×1
html ×1
igraph ×1
list ×1
lxml ×1
matplotlib ×1
matrix ×1
next ×1
python-2.7 ×1
string ×1
time ×1