Skip to content

Instantly share code, notes, and snippets.

@cpelley
Created March 29, 2016 17:17
Show Gist options
  • Save cpelley/894d1f2123868ed87c4ab435db2624ea to your computer and use it in GitHub Desktop.
Save cpelley/894d1f2123868ed87c4ab435db2624ea to your computer and use it in GitHub Desktop.
numpy masked array transpose bug
Display the source blob
Display the rendered blob
Raw
{
"metadata": {
"name": "",
"signature": "sha256:9bf4b5f1b6ea7da9ce1b90545fec8428b4f336bf949bf824cefbf5059fd33482"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": false,
"input": [
"import numpy as np"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"arr = np.ma.arange(12).reshape(3, 4)\n",
"arr.mask = np.random.random_integers(0, 1, 12)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 2
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print arr"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"[[-- -- -- 3]\n",
" [-- 5 -- --]\n",
" [-- 9 10 --]]\n"
]
}
],
"prompt_number": 3
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"arr2 = arr.transpose((1, 0))"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 4
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print arr2.data.base is arr.data\n",
"print arr2.mask.base is arr.mask"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"False\n",
"False\n"
]
}
],
"prompt_number": 5
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"arr3 = arr.reshape(-1)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 6
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print arr3.data.base is arr.data\n",
"print arr3.mask.base is arr.mask"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"False\n",
"True\n"
]
}
],
"prompt_number": 7
}
],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment