使用numpy将范围设置为零(Setting ranges to zero using numpy)

我开始使用numpy cookbook独立学习numpy。 我查看并执行了以下代码:

import scipy.misc
import matplotlib.pyplot

#This script demonstates fancy indexing by setting values
#On the diagnols to 0

#Load lena array
lena = scipy.misc.lena()
xmax = lena.shape[0]
ymax = lena.shape[1]

#Fancy indexing
#can set ranges of points to zero, all at once instead of using loop
lena[range(xmax), range(ymax)] = 0
lena[range(xmax-1,-1,-1), range(ymax)] = 0
matplotlib.pyplot.imshow(lena)
matplotlib.pyplot.show()

我理解这段代码中的所有内容除外:

lena[range(xmax), range(ymax)] = 0
lena[range(xmax-1,-1,-1), range(ymax)] = 0

我阅读关于索引和切片的文档 ,但仍然无法理解上面的代码。 以下是我的困惑点:

1)范围(xmax)和范围(ymax)包括整个x,y轴。 将它们设置为零会使整个图像变黑吗?

2)范围(xmax-1,-1,-1)是什么意思?

多谢你们!


I began independently learning numpy using the numpy cookbook. I reviewed and executed the following code:

import scipy.misc
import matplotlib.pyplot

#This script demonstates fancy indexing by setting values
#On the diagnols to 0

#Load lena array
lena = scipy.misc.lena()
xmax = lena.shape[0]
ymax = lena.shape[1]

#Fancy indexing
#can set ranges of points to zero, all at once instead of using loop
lena[range(xmax), range(ymax)] = 0
lena[range(xmax-1,-1,-1), range(ymax)] = 0
matplotlib.pyplot.imshow(lena)
matplotlib.pyplot.show()

I understand everything in this code except:

lena[range(xmax), range(ymax)] = 0
lena[range(xmax-1,-1,-1), range(ymax)] = 0

I read the documentation on indexing and slicing but still cannot make sense of the above code. Here is are my points of confusion:

1)range(xmax) and range(ymax) encompass the entire x,y axes. Wouldn't setting them to zero make the entire image black?

2)What does range(xmax-1,-1,-1) mean?

Thanks guys!


原文:https://stackoverflow.com/questions/21971483
2023-09-20 19:09

满意答案

正如@Pranav在评论中所述,您可以执行以下操作:

if {condition1} = '0'
  Set @SQLQuery = @SQLQuery + ' AND ' +
                  CASE WHEN {condition2} = 'Yes' THEN <whatever cond2=Yes>
                       ELSE <whatever cond2<>Yes> END

As @Pranav states in the comments, you can do the following:

if {condition1} = '0'
  Set @SQLQuery = @SQLQuery + ' AND ' +
                  CASE WHEN {condition2} = 'Yes' THEN <whatever cond2=Yes>
                       ELSE <whatever cond2<>Yes> END

相关问答

更多

VS2010数据库项目和SQL Server 2008R2(VS2010 Database Projects and SQL Server 2008R2)

好的,我自己想出了这个。 我认为这可能与我卸载一些在Visual Studio中没有清理的连接引用的软件/数据库驱动程序有关。 基本上解决了问题我关闭了Visaul Studio,然后删除了这个文件。 C:\用户\应用程序数据\漫游\微软\ VisualStudio的\ 10.0 \ ServerExplorer \ DefaultView.SEView 以下是帮助我解决的问题和答案的链接: http : //connect.microsoft.com/VisualStudio/feedback/...

SQL Server(2008R2)可以优化Sybase Join语法(Can SQL Server (2008R2) optimise Sybase Join Syntax)

是的,SQL Server可以优化它。 我在我的SQL Server 2012实例上运行了它,它为我提供了两个查询的相同执行计划: SELECT [T2].[c3], [T1].[c3] FROM [dbo].[T2] T2, [dbo].[T1] T1 WHERE [T2].[ID] = [T1].[ID] 和 SELECT [T2].[c3], [T1].[c3] FROM [dbo].[T2] T2 INNER JOIN [dbo].[T1] T1 ON [T2].[ID] = [T...

Sql Server 2008R2 XML导出(Sql Server 2008R2 XML export)

如果要在sprProduct中嵌套priceBracket,则将所选XML列别名为[sprProduct/priceBracket] 。 要创建嵌套节点的属性,请使用@前缀,例如[sprProduct/priceBracket/@quanity] 。 这是一个示例脚本,显示如何创建您提到的不同安排。 select -- row level attributes 1 as [@a], 2 as [@b], 3 as [@c], -- node level at...

跨服务器查询在SQL Server 2008R2中不起作用(Cross-server query does not work in SQL Server 2008R2)

您需要创建指向其他服务器的链接。 您可以使用sp_addlinkedserver存储过程或通过Sql Server Management Studio gui执行此操作。 You need to create a link to the other servers. You can do this with the sp_addlinkedserver stored procedure or via the Sql Server Management Studio gui.

如何在SQLServer 2008R2中跨多行查询xml(How to query xml across multiple rows in SQLServer 2008R2)

如果您的XML在XML列中定义.. DECLARE @Items AS TABLE ( ItemXml XML ) -- test data with a couple rows of xml INSERT INTO @Items(ItemXml) VALUES ('<Items><Item>Item 1</Item><Item>Item 2</Item></Items>') ,('<Items><Item>Item 3</Item><Item>Item 4</Item><...

SQL Server 2008 R2用户定义函数(表值)性能(SQL Server 2008R2 User Defined Function (Table valued) Performance)

有多种方法来编写一个表值函数。 使用AS RETURN的语法是“内联表值函数”。 这相当于一个视图。 SQL Server将在执行语句时扩展该函数。 调用这种函数没有任何开销。 “多语句表值函数”不等同于视图。 优化程序不能“内联”多个语句,因此“多语句TVL”通常会产生大量开销。 There are multiple ways to write a table-valued function. The syntax you're using, with AS RETURN, is an "inl...

如何在Sql server 2008R2中搜索日期时间(How to Search datetime in Sql server 2008R2)

您必须投射到目前为止比较两个相等的日期。 例如 CAST(registration_date AS DATE) = CAST('2014-06-19' AS DATE) 替代: DECLARE @DateToFilter DATE = (CAST('2014-06-19' AS DATE)) [..] WHERE registration_date >= @DateToFilter AND registration_date < DATEADD(d, 1, @DateToFilter) ...

SQL Server 2008R2加入一对多(SQL Server 2008R2 Join One To Many)

尝试这个: select * from case C left join P on P.case_id = C.case_id and P.primary_party != '' where P.case_id is null 这将选择所有没有关联的非空主要聚会的案例。 作为旁注,我建议使用null来表示“无主要派对”而不是空字符串。 Try this: select * from case C left join P on P.case_id = C.case_id and P.primary...

如何优化嵌套条件SQL Server查询2008R2(How to optimize nested conditional SQL Server Query 2008R2)

正如@Pranav在评论中所述,您可以执行以下操作: if {condition1} = '0' Set @SQLQuery = @SQLQuery + ' AND ' + CASE WHEN {condition2} = 'Yes' THEN <whatever cond2=Yes> ELSE <whatever cond2<>Yes> END As @Pranav states in the comment...

我应该在我刚刚添加到MS SQL Server 2008R2列的索引的Rails模型定义中添加什么?(What should I put in the Rails model definition for the index I just added to a MS SQL Server 2008R2 column?)

Afaik Rails不关心数据库的索引。 在Rails中没有基于索引的查询优化。 如果对列进行排序或过滤(特别是在大表上),添加索引会很有帮助。 这有助于您的数据库服务器更有效地执行这些操作。 但是,添加索引的更好方法是让Rails通过迁移来做,而不是手动执行。 可能是因为SQL也被剪断了。 这可确保索引适用于所有环境和服务器。 为什么在Rails中需要很长时间我不知道。 但您可以在迁移中运行SQL: def up execute "ALTER TABLE orders ADD UNIQUE...

相关文章

更多

Setting up Nutch 2.1 with MySQL to handle UTF-8

原文地址:http://nlp.solutions.asia/?p=180 These instruc ...

Solr 4.6 | Setting Up an External ZooKeeper Ensemble | upgrade solr to Solr4.6

4.1-----&gt;4.6 Solr从4.1到4.6还是有不少改变的。。。 一、solr.xml ...

grep 零宽断言

原文链接 参考 参考二 算是正则环视的一个简单应用吧。 http://pengqi.me/201 ...

solr 从零学习开始

开源企业搜索引擎SOLR的 应用教程 2010-10 目 录 1 概述... 4 1.1 企业搜索引擎 ...

solr 从零学习开始

1 概述 1.1 企业搜索引擎方案选型 由于搜索引擎功能在门户社区中对提高用户体验有着重在门户社区中 ...

关于eclipse的设置问题

在eclipse里打开一个文件,会自动帮你打开所在的包,换句话说就是自动帮你定位到所在的包 有时候找 ...

经典的机器学习方面源代码库(非常全,数据挖掘,计算机视觉,模式识别,信息检索相关领域都适用的了)

今天给大家介绍一下经典的开源机器学习软件: 编程语言:搞实验个人认为当然matlab最灵活了(但是正版 ...

[repost ]经典的机器学习方面源代码库

[repost ]经典的机器学习方面源代码库: original:http://b ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本