<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>scienceoss.com &#187; array</title>
	<atom:link href="http://scienceoss.com/tags/array/feed/" rel="self" type="application/rss+xml" />
	<link>http://scienceoss.com</link>
	<description>useful tidbits for using open source software in science</description>
	<lastBuildDate>Wed, 26 May 2010 03:34:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>&#8220;Vectorization&#8221; in NumPy</title>
		<link>http://scienceoss.com/vectorization-in-numpy/</link>
		<comments>http://scienceoss.com/vectorization-in-numpy/#comments</comments>
		<pubDate>Fri, 21 Mar 2008 14:10:39 +0000</pubDate>
		<dc:creator>ryan</dc:creator>
				<category><![CDATA[NumPy]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[boolean]]></category>
		<category><![CDATA[indexing]]></category>
		<category><![CDATA[logical operators]]></category>
		<category><![CDATA[vectorization]]></category>

		<guid isPermaLink="false">http://scienceoss.com/vectorization-in-numpy/</guid>
		<description><![CDATA[How do you get Matlab-like vectorization when using NumPy? The key is using parentheses when using logical operators. Here&#8217;s an example: from numpy import * a = array([1,2,3,4,5]) b = array([5,4,3,2,1]) c = array([1,2,2,2,1]) # ===The right way=== (a3) &#038; (c==2) # array([ False, True, False, False, False], dtype=bool) # ===The wrong way=== a3 &#038; [...]]]></description>
			<content:encoded><![CDATA[<p>How do you get Matlab-like vectorization when using NumPy?  The key is using parentheses when using logical operators.  Here&#8217;s an example:</p>
<pre class="prettyprint"><code class="code">from numpy import *

a = array([1,2,3,4,5])
b = array([5,4,3,2,1])
c = array([1,2,2,2,1])

# ===The right way===

(a<5) &#038; (b>3) &#038; (c==2)
# array([ False,  True, False, False, False], dtype=bool)

# ===The wrong way===

a<5 &#038; b>3 &#038; c==2
# ValueError:
# The truth value of an array with more than
# one element is ambiguous. Use a.any() or a.all()</code></pre>
<p>Alternatively, use NumPy&#8217;s <span class="c">logical_and</span> and <span class="c">logical_or</span> functions . . . but these functions only take two arguments at a time.</p>
]]></content:encoded>
			<wfw:commentRss>http://scienceoss.com/vectorization-in-numpy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Check the type of array in Numpy</title>
		<link>http://scienceoss.com/check-the-type-of-array-in-numpy/</link>
		<comments>http://scienceoss.com/check-the-type-of-array-in-numpy/#comments</comments>
		<pubDate>Mon, 17 Mar 2008 00:55:39 +0000</pubDate>
		<dc:creator>ryan</dc:creator>
				<category><![CDATA[BioPython]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[type]]></category>

		<guid isPermaLink="false">http://scienceoss.com/check-the-type-of-array-in-numpy/</guid>
		<description><![CDATA[from numpy import array a = array([1,2,3]) a.dtype # dtype('int32') a.dtype.kind # 'i', for 'integer' s = array(['a','b','c']) s.dtype # dtype('&#124;S1') s.dtype.kind # 'S' for 'string' f = array([1., 2., 3.]) f.dtype # dtype('float64') f.dtype.kind # 'f' for 'float']]></description>
			<content:encoded><![CDATA[<pre class="prettyprint"><code class="code">from numpy import array
a = array([1,2,3])
a.dtype  # dtype('int32')
a.dtype.kind  # 'i', for 'integer'

s = array(['a','b','c'])
s.dtype  # dtype('|S1')
s.dtype.kind  # 'S' for 'string'

f = array([1., 2., 3.])
f.dtype  # dtype('float64')
f.dtype.kind  # 'f' for 'float'</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://scienceoss.com/check-the-type-of-array-in-numpy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

