想象一下,我们有一个5x4矩阵.我们只需删除第一个维度.我们怎么能用numpy做到这一点?
array([[ 0., 1., 2., 3.],
[ 4., 5., 6., 7.],
[ 8., 9., 10., 11.],
[ 12., 13., 14., 15.],
[ 16., 17., 18., 19.]], dtype=float32)
Run Code Online (Sandbox Code Playgroud)
我试过了:
arr = np.arange(20, dtype=np.float32)
matrix = arr.reshape(5, 4)
new_arr = numpy.delete(matrix, matrix[:,0])
trimmed_matrix = new_arr.reshape(5, 3)
Run Code Online (Sandbox Code Playgroud)
它看起来有点笨重.我做得对吗?如果是,是否有更简洁的方法来移除尺寸而不重塑?
我根据此答案设置了基于URL的数据库路由,以便为不同的项目/数据库使用相同的应用程序.项目不需要共享任何数据,访问控制由每个项目自己管理,我需要每个项目的管理站点.与原始帖子一样,我使用数据库路由器和中间件来确定从请求路径使用哪个数据库,例如/test/process/1将路由到数据库test和/default/process/2数据库default.
import threading
from django.conf import settings
request_cfg = threading.local()
class RouterMiddleware(object):
def process_view(self, request, view_func, view_args, view_kwargs):
path = request.path.lstrip('/').split('/')
if path[0] in settings.DATABASES:
request_cfg.db = path[0]
def process_response(self, request, response):
if hasattr(request_cfg, 'db'):
del request_cfg.db
return response
class DatabaseRouter(object):
def _default_db(self):
if hasattr(request_cfg, 'db') and request_cfg.db in settings.DATABASES:
return request_cfg.db
else:
return 'default'
def db_for_read(self, model, **hints):
return self._default_db()
def db_for_write(self, model, **hints):
return self._default_db()
Run Code Online (Sandbox Code Playgroud)
然后需要扩展url模式以包括引用特定数据库的子路径.我通过硬编码项目级urls.py中的url来做到这一点,如下所示:
urlpatterns = …Run Code Online (Sandbox Code Playgroud) 我注意到scipy.ndimage.zoom的结果取决于原始图像的大小。在下面的代码示例中,将生成一个棋盘图像,然后使用ndimage.zoom进行缩放。如果一个棋盘格拼贴仅为2x2像素,则缩放系数似乎太大,并且裁剪出了生成的图像。相反,如果图块的尺寸为10x10,则结果看起来不错。
from __future__ import division
import numpy as np
from scipy import ndimage, misc
import wx
y,x = 2,2 # change tile size here
imgdata = np.zeros((y,x),dtype='uint8')
imgdata[y/2:,x/2:] = 255
imgdata[:y/2,:x/2] = 255
imgdata = np.tile(imgdata,(4,4))
imgdata = np.array((imgdata,imgdata,imgdata))
d,y,x = imgdata.shape
zoom = 200.0/y
w, h = int(x*zoom), int(y*zoom)
app = wx.App(None)
zoomed = np.ascontiguousarray(ndimage.interpolation.zoom(imgdata,[1,zoom, zoom],order=0).transpose((1,2,0)), dtype='uint8')
image = wx.ImageFromBuffer(w, h, zoomed)
image.SaveFile('zoomed.png',wx.BITMAP_TYPE_PNG)
Run Code Online (Sandbox Code Playgroud)
据我所知,我一直在使用scipy.misc.imresize,它没有显示此行为,但我想避免对PIL的其他依赖。
我是在做错什么还是缩放错误?
有人能够向我解释如何在Scipy中使用location参数和gamma.fit函数吗?
在我看来,位置参数(μ)将分布的支持从x≥0改变为y =(x-μ)≥0.如果μ为正,那么我们不会丢失所有不满足的数据x - μ≥0?
谢谢!
def new_presentation():
prs=Presentation()
img="C:/Users/Dennis/Desktop/Tom-Hiddleston-4-1024x768.jpg"
mainsld=new_slide(prs, 6)
mainshp=mainsld.shapes
mainshp.add_picture(img, 0,0, Inches(10))
titleshape=mainshp.add_shape(MSO_SHAPE.RECTANGLE, Inches(0), Inches(1), Inches(10), Inches(1))
titleshape.fill.solid()
titleshape.fill.fore_color.rgb=RGBColor(0x00,0x64,0x00)
titleshape.fill.transparency = 0.25 ##doesnt work???##########################
titleshape.line.fill.background()
titlebox=mainshp.add_textbox(Inches(1), Inches(0.8),Inches(1), Inches(1)).text_frame.add_paragraph()
titlebox.text="TOM HIDDLESTON"
titlebox.font.name="Calibri"
titlebox.font.size=Pt(36)
titlebox.font.color.rgb=RGBColor(0x90,0x90,0x00)
prs.save('test.pptx')
Run Code Online (Sandbox Code Playgroud)
标有“######s”的行应该使形状更加透明,如 pptx 文档中所写 - 它是 shape.fill 属性。代码中的其他所有内容都完美运行。我正在使用 python 2.7 和最新的 pptx。提前谢谢你的帮助。
python ×5
scipy ×2
arrays ×1
distribution ×1
django ×1
gamma ×1
ndimage ×1
numpy ×1
presentation ×1
python-2.7 ×1
python-pptx ×1
transparency ×1