Created
November 2, 2014 13:36
-
-
Save immerrr/ab4a50a665844c2293aa to your computer and use it in GitHub Desktop.
PyArray_IsAnyScalar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"metadata": { | |
"name": "", | |
"signature": "sha256:040529abaecd9dccb951fb2476b50919c94f971232d421e042dddd5904ac5e5c" | |
}, | |
"nbformat": 3, | |
"nbformat_minor": 0, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"%load_ext cythonmagic" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 1 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"%%cython\n", | |
"\n", | |
"from cpython cimport *\n", | |
"\n", | |
"cimport numpy as cnp \n", | |
"cnp.import_array()\n", | |
"\n", | |
"def isanyscalar(obj):\n", | |
" return cnp.PyArray_IsAnyScalar(obj)\n", | |
"\n", | |
"\n", | |
"def isstring(obj):\n", | |
" return PyString_Check(obj)\n", | |
"\n", | |
"def isunicode(obj):\n", | |
" return PyUnicode_Check(obj)\n", | |
"\n", | |
"def isbytes(obj):\n", | |
" return PyBytes_Check(obj)" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 6 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"x = b'foobar'\n", | |
"print (isstring(x))\n", | |
"print (isunicode(x))\n", | |
"print (isbytes(x))\n", | |
"print (isanyscalar(x))" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"False\n", | |
"False\n", | |
"True\n", | |
"False\n" | |
] | |
} | |
], | |
"prompt_number": 9 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [] | |
} | |
], | |
"metadata": {} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment