array

Matplotlib: save plot to numpy array

匿名 (未验证) 提交于 2019-12-03 08:57:35
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: In Python and Matplotlib, it is easy to either display the plot as a popup window or save the plot as a PNG file. How can I instead save the plot to a numpy array in RGB format? 回答1: This is a handy trick for unit tests and the like, when you need to do a pixel-to-pixel comparison with a saved plot. One way is to use fig.canvas.tostring_rgb and then numpy.fromstring with the approriate dtype. There are other ways as well, but this is the one I tend to use. E.g. import matplotlib.pyplot as plt import numpy as np # Make a random plot... fig =

Numpy vs Cython speed

匿名 (未验证) 提交于 2019-12-03 08:57:35
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have an analysis code that does some heavy numerical operations using numpy. Just for curiosity, tried to compile it with cython with little changes and then I rewrote it using loops for the numpy part. To my surprise, the code based on loops was much faster (8x). I cannot post the complete code, but I put together a very simple unrelated computation that shows similar behavior (albeit the timing difference is not so big): Version 1 (without cython) import numpy as np def _process(array): rows = array.shape[0] cols = array.shape[1] out =

jQuery get multiple attributes

匿名 (未验证) 提交于 2019-12-03 08:57:35
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have an element I need to get an array of specific attributes. For example: <div id="myDiv" class="myClass" data-country="US" data-city="NY" /> In this example, I need to get all data-* attributes and place them in array (name and value pairs). In this example, final array would look like this: myDataArray["data-country"] = "US"; myDataArray["data-city"] = "NY"; Problem is that these attributes are dynamic, I do not know what attributes will be there at the runtime and I cannot hard code filling of array. 回答1: You can call data() to get

find number with no pair in array

匿名 (未验证) 提交于 2019-12-03 08:57:35
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am having trouble with a small bit of code, which in a random size array, with random number pairs, except one which has no pair. I need to find that number which has no pair. arLength is the length of the array. but i am having trouble actually matching the pairs, and finding the one which has no pair.. for (int i = 0; i <= arLength; i++) { // go through the array one by one.. var number = nArray[i]; // now search through the array for a match. for (int e = 0; e <= arLength; e++) { if (e != i) { } } } I have also tried this : var

Finding EVEN number of times repeating integer in an array where rest of the integers repeat ODD number of times

匿名 (未验证) 提交于 2019-12-03 08:56:10
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Given is an array of integers. Each number in the array occurs an ODD number of times, but only 1 number is occurring an EVEN number of times. Find that number. Below is the solution I read on stackoverflow that does NOT work. I am unable to find the link to that solution and I was wondering if somebody could help me understand why this solution is incorrect unless I am doing something wrong below. We first XOR all the elements in the array. Lets call it aWithOutDuplicate which contains all the odd elements except for duplicate one. We then

Rearrange array index Eloquent Laravel

匿名 (未验证) 提交于 2019-12-03 08:56:10
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have an error after delete an element from an array of laravel eloquent A property has rooms foreach ($property->rooms as $key => $room) { if ($room->type == 1 and $type ==1 and $room->price < $price->min or $room->price > $price->max) { print_r($property->rooms); unset($property->rooms[$key]); //$array = array_values($property->rooms); doesn't work print_r($property->rooms); } } When i encode this into a json, the array is convert into an object not an array Before unset Illuminate\Database\Eloquent\Collection Object ( [items:protected] =

Deadlocks while passing ARRAY to stored proc

匿名 (未验证) 提交于 2019-12-03 08:54:24
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: While sending ARRAY to the stord proc we are getting java level dead locks. I am attaching the thread dump. Found one Java-level deadlock: ============================= "http-bio-8080-exec-11": waiting to lock monitor 0x00000000406fb2d8 (object 0x00000000fea1b130, a oracle.jdbc.driver.T4CConnection), which is held by "http-bio-8080-exec-4" "http-bio-8080-exec-4": waiting to lock monitor 0x00000000407d6038 (object 0x00000000fe78b680, a oracle.jdbc.driver.T4CConnection), which is held by "http-bio-8080-exec-11" Java stack information for the

Working with TIFFs (import, export) in Python using numpy

匿名 (未验证) 提交于 2019-12-03 08:54:24
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I need a python routine that can open and import TIFF images into numpy arrays, so I can analyze and modify the contained data and afterwards save them as TIFFs again. (They are basically light intensity maps in greyscale, representing the respective values per pixel) I tried to find something, but there is no documentation on PIL methods concerning TIFF. I tried to figure it out, but only got bad mode/ file type not supported errors. What do I need to use here? 回答1: First, I downloaded a test TIFF image from this page called a_image.tif .

Typescript create array with loop dynamically

匿名 (未验证) 提交于 2019-12-03 08:54:24
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Am creating a mock class, for generate example data for my Angular2 TypeScript project. Am still a beginner with programming, and struggle with the informatie that is available about TypeScript. My question: I want to create 100 items and save them in an array. The 100 items will be generated dynamically. The static way i use is very simple, but how do I can do this dynamicly? I made a begin with some iteration code, but how can I best replace the console.log code, and let the output of the iteration be as the static data. I need some

CakePHP containable conditions not limiting results?

匿名 (未验证) 提交于 2019-12-03 08:54:24
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to find a User's grocery items in a categorized list. The associations are Category hasMany Item hasMany User through Grocery. I'm using the Containable Behavior and it is not filtering out all other Grocery. It returns every item basically. My controller function: function showlist() { $categories = $this->Category->find('all', array( 'contain' => array( 'Item' => array( 'Grocery' => array( 'conditions' => array( 'Grocery.user_id =' => $this->Auth->user('id') ) ) ) ) )); Array that's returned: Array ( [0] => Array ( [Category] =>