使用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
满意答案
正如@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)
SQL Server(2008R2)可以优化Sybase Join语法(Can SQL Server (2008R2) optimise Sybase Join Syntax)
Sql Server 2008R2 XML导出(Sql Server 2008R2 XML export)
跨服务器查询在SQL Server 2008R2中不起作用(Cross-server query does not work in SQL Server 2008R2)
如何在SQLServer 2008R2中跨多行查询xml(How to query xml across multiple rows in SQLServer 2008R2)
SQL Server 2008 R2用户定义函数(表值)性能(SQL Server 2008R2 User Defined Function (Table valued) Performance)
如何在Sql server 2008R2中搜索日期时间(How to Search datetime in Sql server 2008R2)
SQL Server 2008R2加入一对多(SQL Server 2008R2 Join One To Many)
如何优化嵌套条件SQL Server查询2008R2(How to optimize nested conditional SQL Server Query 2008R2)
我应该在我刚刚添加到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?)
相关文章
更多Setting up Nutch 2.1 with MySQL to handle UTF-8
Solr 4.6 | Setting Up an External ZooKeeper Ensemble | upgrade solr to Solr4.6
grep 零宽断言
solr 从零学习开始
solr 从零学习开始
关于eclipse的设置问题
经典的机器学习方面源代码库(非常全,数据挖掘,计算机视觉,模式识别,信息检索相关领域都适用的了)
经典的机器学习方面源代码库(非常全,数据挖掘,计算机视觉,模式识别,信息检索相关领域都适用的了)
经典的机器学习方面源代码库(非常全数据挖掘,计算机视觉,模式识别,信息检索相关领域都适用的了)
[repost ]经典的机器学习方面源代码库
最新问答
更多获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
如何通过引用返回对象?(How is returning an object by reference possible?)
矩阵如何存储在内存中?(How are matrices stored in memory?)
每个请求的Java新会话?(Java New Session For Each Request?)
css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
xcode语法颜色编码解释?(xcode syntax color coding explained?)
在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!